package helloworld;
public class windspeed {
public static void main(String args[]) {
int t = Integer.parseInt(args[44]); //this is the array input for temperature
int v = Integer.parseInt(args[15]); //this is the array input for wind speed
double x = Math.pow(v, 0.16); //this is the exponent math for the end of the equation
if (t < 0) {
t = t*(-1); //this is the absolute value for temperature
}
double w = (35.74 + 0.6215*t)+((0.4275*t - 35.75)* x); //this is the actual calculation
if (t<=50 && v>3 && v<120) { //this is so the code runs only when the equation works
System.out.println(w);
}
if (t>50 || v<3 || v>120){
System.out.println("The wind chill equation doesn't work with these inputs, try again.");
}
}
}
这给了我一个ArrayIndexOutOfBounds
错误。无论我在[]
中输入什么内容,都会出现错误...为什么?我该如何解决它?Java数组索引越界异常的不管数组长度
什么'System.out.println(args.length);'在控制台中显示? (把它作为在main方法的第一行) – Craig
好像你没有使用ARGS正确:http://docs.oracle.com/javase/tutorial/essential/environment/cmdLineArgs.html – Radiodef
添加'的System.out .println(args.length)'到顶部,并查看发生了什么 – dognose