代码不会输入正确的if语句

时间:2015-03-31 11:27:24

标签: java

下面的代码在调试模式下正常执行,但是当我运行它时,我遇到了if语句的以下问题:

即使t == 0,它也会进入else块,而不是进入if块。我还尝试删除else并撰写if (t > 0),但这不起作用。

for (t = 0; t < T; t++) {
    for (i = 0; i < 6; i++) {
        for (j = 0; j < 6; j++) {
            if (t == 0) {
                // Lines of code..... 
            } else {
                // Lines of code....
            }
        }
    }
}

2 个答案:

答案 0 :(得分:0)

试试这个:

if (t < 1) {
    // Lines of codes..... 
} else {
    // Lines of codes....
}

t小于1时会触发。

答案 1 :(得分:-2)

根据您所写的内容,我假设您在t为特定值时打印第一个输出。如果将if语句更改为(t <1),则应执行第二个输出。

public class StackOverflow 
{
public static void main(String[] args)
{
    int t, j, i;
    int T = 6;

    for (t = 0; t < T; t++) 
    {
        for (i = 0; i < 6; i++) 
        {
            for (j = 0; j < 6; j++) 
            {
                if (t < 0) 
                {
                    // Lines of codes.....
                    System.out.println("Output 1");
                } 
                else 
                {
                    // Lines of codes....
                    System.out.println("Output 2");
                }
            }
        }
    }
}
}
相关问题