如果我在下面的代码下运行,我是Java编码的新手。请参阅错误。
public class LeapYear {
public static void main(String[] args) {
int a = Integer.parseInt(args[0]);
int b = Integer.parseInt(args[1]);
int sum = a + b;
int prod = a * b;
int quot = a / b;
int rem = a % b;
System.out.println(a + " + " + b + " = " + sum);
System.out.println(a + " * " + b + " = " + prod);
System.out.println(a + " / " + b + " = " + quot);
System.out.println(a + " % " + b + " = " + rem);
System.out.println(a + " = " + quot + " * " + b + " + " + rem);
}
}
O / p :::
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at LeapYear.main(LeapYear.java:4)
答案 0 :(得分:0)
如果是在netbeans上运行,则可以通过右键单击项目,选择属性(位于底部),单击运行类别,然后在Runtime Platform和Main Class下面,将参数传递给main方法。一个用于输入参数的文本字段。
如果您是从命令行调用的,例如运行javac并将其传递为主类名,只需在类名后添加两个命令行参数即可。