嗨每个人我都在练习Java语言。我面临这个问题。我是这种语言的初学者。我正在研究它,在我的拼贴画中。这是问题。我编译我的程序时出现错误(异常在线程“main”java.lang.ArrayIndexOutOfBoundsException)
“创建Java程序,将得到一个数字的总和。例如,5的输入会产生(1 + 2 + 3 + 4 + 5 = 15)”
我知道答案,但我试图用另一种方式解决它。在Java中开始
public class Sum11 {
static int i;
static int[] S = new int[5];
static int j;
static int Sum = 0;
Sum11(int i,int S[],int j){
this.S=S;
this.i=i;
this.j=j;
}
public static void main(String[] args){
Scanner s1 = new Scanner(System.in);
for(i=1;i<=5;i++){
System.out.println("Enter FIve Number");
S[i]= s1.nextInt();
}
for(int num : S){
Sum = Sum+num;
}
System.out.println("The Result IS: "+Sum);
}
}
谢谢你的人,帮助我很多 – Moayad