Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java SE 综合讨论区 » 实战错误讨论  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 问题在哪里!(ArrayIndexOutOfBoundsException)
fossil





发贴: 15
积分: 0
于 2005-08-23 19:09 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
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)
好像是数组的长度问题!但我不会!大家帮帮忙!


why edited on 2005-08-23 20:55


话题树型展开
人气 标题 作者 字数 发贴时间
7570 问题在哪里!(ArrayIndexOutOfBoundsException) fossil 1523 2005-08-23 19:09
6226 Re:大家帮我看看我的问题在哪里! truthawp 473 2005-08-23 20:50
5862 Re:大家帮我看看我的问题在哪里! CunningFox 715 2005-09-23 14:05
5994 Re:问题在哪里!(ArrayIndexOutOfBoundsException) fossil 25 2005-08-24 10:18
5831 Re:问题在哪里!(ArrayIndexOutOfBoundsException) why 114 2005-08-24 11:22
6191 Re:问题在哪里!(ArrayIndexOutOfBoundsException) fly135 25 2005-09-23 18:24

flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923