Please use the [ code ] tag for source code.
请尽量使用准确的文字描述作为标题
Your next post without a proper Subject will be removed.
Original subject : 大家帮我看看我的问题在哪里!
import java.io.*;
public class max
{
public static void main(String[] args)
{
int[] test=new int[5];
int max;
max=0;
int index=0;
while (index<test.length)
{
System.out.print("请输入第"+(index+1)+"个数");
try{
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String inputLine=in.readLine();
test[index] = Integer.valueOf(inputLine).intValue();
}
catch(Exception exc){
System.out.println("输入的数字不合法");
continue;
}
index=index+1;
}
max=test[0];
System.out.println(test[0]);
for (int i=0;i<test.length ;i++ )
{
if (test[i]>=test[i+1])
max=test[i];
}
System.out.println("最大数为"+max);
}
}
最后输完5个数后出来:Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException
at max.main(max.java:36)
好像是数组的长度问题!但我不会!大家帮帮忙!