[英]Can't see why this won't work | Loop won't run
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++)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.