第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

我想運行我的代碼,但終端告訴索引越界??赡苁且驗?ArrayList 方法會像這樣

我想運行我的代碼,但終端告訴索引越界??赡苁且驗?ArrayList 方法會像這樣

白板的微信 2021-06-22 17:01:00
我正在嘗試運行我的代碼。但終端告訴:Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 1, Size: 1    at java.util.ArrayList.rangeCheck(Unknown Source)    at java.util.ArrayList.get(Unknown Source)    at CF455A.main(CF455A.java:25)第 25 個字符串是: game.remove(game.get(max+1)); 我的代碼:import java.util.*;import java.lang.*;import java.io.*;public class CF455A { public static void main(String args[]) throws java.lang.Exception {     Scanner in = new Scanner (System.in);     int n = in.nextInt();     int max = 0;     ArrayList<Integer> game = new ArrayList<Integer>();    for(int i = 0; i < n; i++){        int t = in.nextInt();        game.add(i, t);    }    int counter = 0;    while(game.size()>0){        for(int j = 0; j < game.size(); j++){            if(max <= (int)game.get(j)){max=j;}            for(int i = 0; i < game.size(); i++){                counter = counter + (int)game.get(max);                game.remove(game.get(max));                game.remove(game.get(max+1));                game.remove(game.get(max-1));            }        }    }    System.out.print(counter);    in.close();}我認為這是因為 ArrayList 或像game.get();or 之類的方法game.remove();。我只是想更改 ArrayList 的元素之一的值
查看完整描述

1 回答

  • 1 回答
  • 0 關(guān)注
  • 126 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號