无法看到为什么这行不通|循环将无法运行 [英] Can't see why this won't work | Loop won't run

查看:73
本文介绍了无法看到为什么这行不通|循环将无法运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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(输入数字.");

When the user types the answer to this: System.out.println("Type the numbers.");

它不会继续到我的代码的下一部分.

It won't continue to the next part of my code.

很抱歉,如果是重新发布,但我一直在寻找一些类似的东西,但找不到.

Sorry if it's a repost, but I kept searching for some time for something like this, but couldn't find.

推荐答案

您的for循环进行5次迭代,而不是4次.您应从终止子句中删除=,以使其正常运行. for(int i = 0; i < numeros.length; i++)

Your for loop goes for 5 iterations, not 4. You should remove the = from the terminating clause in order to get it working. for(int i = 0; i < numeros.length; i++)

这篇关于无法看到为什么这行不通|循环将无法运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆