我一直在尝试在同一个数组中添加一些数字。我怎么会收到 java.lang.ArrayIndexOutOfBoundsException: 5 错误。我已经尝试过
for(int 1 : array)
在我这样做之后,我收到错误 java.lang.ArrayIndexOutOfBoundsException: 12
我应该如何尝试解决这个问题?我是游戏开发的一年级学生,所以当你试图向我解释时请记住这一点。谢谢你。
我的完整代码是:
package com.company;
导入 java.util.Scanner;
公共类 BsaMonitor2 {
public static void main(String[] args) {
int totalStudiePunt = 0;
String[] vakNamen = {"FYS", //12 studie punten
"Programming", "Databases", "Game Basics", "User Interaction", //3 studie punten
"Personal Skills", "Project Skills", "Wiskunde", //2 studie punten
"Nederlands", "English"}; //1 studie punt
double[] cijfers = new double[10];
int[] studiePunten = {12, 3, 2, 1, 0};
Scanner input = new Scanner(System.in);
for (int iVak = 0; iVak < 10; iVak++) {
while (cijfers[iVak] <= 0.9 && cijfers[iVak] >= 10.1) {
System.out.print(vakNamen[iVak] + ": ");
cijfers[iVak] = input.nextDouble();
}
}
for (int iVak = 0; iVak < 10; iVak++) {
while (cijfers[iVak] <= 1 || cijfers[iVak] >= 10) {
System.out.print(vakNamen[iVak] + ": ");
cijfers[iVak] = input.nextDouble();
}
}
for (int iCijfers = 0; iCijfers < 1; iCijfers++) {
if(cijfers[iCijfers] >= 5.5) {
System.out.printf("Vak/project: %-17s Cijfer %2.1f Studiepunten: %d \n", vakNamen[iCijfers], cijfers[iCijfers], studiePunten[0]);
}
else{
System.out.printf("Vak/project: %-17s Cijfer %2.1f Studiepunten: %d \n", vakNamen[iCijfers], cijfers[iCijfers], studiePunten[4]);
}
}
Smart猫小萌
相关分类