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