作者hahehohe (280)
看板java
标题[问题] java初学者出入问题
时间Fri Nov 5 15:01:49 2010
这是我写的程式
import java.util.Scanner;
public class hw2 {
public static void main(String[]args)
{
int total,average;
Scanner scanner= new Scanner(System.in);
System.out.print("please input chinese score:");
int chinese= Integer.parseInt(args[0]);
System.out.print("please input math score:");
int math= Integer.parseInt(args[1]);
System.out.print("please input english score:");
int english= Integer.parseInt(args[2]);
total= chinese+math+english;
average= total/3;
System.out.println(chinese);
}
}
可是每次跑的时候他都会出现
please input chinese score:Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at hw2.main(hw2.java:19)
不知道哪里出错了@@ 可以帮我看一下吗
谢谢喔
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 111.82.198.164
1F:→ darkk6:"hw2.java:19" 有跟你说哪边错了 11/05 15:05
2F:→ brianhsu:args 是命令列参数,你执行时没给当然就炸掉了。 11/05 16:01
3F:→ a1234957:一定是你跑的时候没给参数 11/05 18:13