リストに入れたものを繰り返し取り出したいのですが、エラーになってしまいます。
JAVA
1Scanner sc = new Scanner(System.in); 2List<Double> al = new ArrayList<Double>(); 3 int b = -1; 4 for(int j = 0; j < camera; j++) { 5 x = sc.nextDouble(); 6 y = sc.nextDouble(); 7 dirAngle = sc.nextDouble(); 8 viewAngle = sc.nextDouble(); 9 distance = sc.nextDouble(); 10 al.add(x); 11 al.add(y); 12 al.add(dirAngle); 13 al.add(viewAngle); 14 al.add(distance); 15 16 } 17 18 for(int i = 0; i < mono ; i++) { 19 px = sc.nextDouble(); 20 py = sc.nextDouble(); 21 22 double a = Math.toDegrees(Math.atan2(py - al.get(b + 2), px - al.get(b + 1))); 23 if (a < 0) { 24 a += 360.0; 25 } 26 27 double aMin = al.get(b + 3) - al.get(b + 4)/2; 28 if (aMin < 0.0) { 29 aMin += 360; 30 } 31 32 b += 5; 33 }
エラー;
Exception in thread "main" java.lang.IndexOutOfBoundsException: Index 5 out of bounds for length 5
at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:64)
at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:70)
at java.base/jdk.internal.util.Preconditions.checkIndex(Preconditions.java:248)
at java.base/java.util.Objects.checkIndex(Objects.java:359)
at java.base/java.util.ArrayList.get(ArrayList.java:427)
at Main.main(Main.java:50)
回答2件
あなたの回答
tips
プレビュー