public static void main(String[] args) {
Scanner xis = new Scanner(System.in);
int H1 = 0;
int M1 = 0;
int H2 = 0;
int M2 = 0;
int[] numeros = new int[4];
System.out.println("Type the numbers.");
for(int i = 0; i <= numeros.length; i++)
{
numeros[i] = xis.nextInt();
H1 = H1 + numeros[0];
M1 = M1 + numeros[1];
H2 = H2 + numeros[2];
M2 = M2 + numeros[3];
}
System.out.println(H1);
System.out.println(H2);
int horaDuracao = (H2 - H1) * -1;
int minutoDuracao = (M2 - M1) * -1;
if(horaDuracao <= 0)
{
horaDuracao = horaDuracao + 24;
}
if (minutoDuracao <= 0)
{
minutoDuracao = minutoDuracao + 59;
horaDuracao = horaDuracao + -1;
}
}
当用户输入答案时: System.out.println("输入数字。");
它不会继续到我的代码的下一部分。
抱歉,如果这是转发,但我一直在寻找类似的东西一段时间,但找不到。
最佳答案
您的 for 循环进行了 5 次迭代,而不是 4 次。您应该从终止子句中删除 = 才能使其正常工作。
for(int i = 0; i < numeros.length; i++)
关于java - 不明白为什么这行不通 |循环不会运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29639110/