我的if语句将默认为错误的

时间:2016-05-27 01:56:08

标签: java if-statement

    if (SuperTotal [0] == SuperTotal [1] && SuperTotal [0] == SuperTotal [2])
    {
        System.out.println ("1First: " + name [0] + ", " + name [1] + ", " + name [2]);
    }
    //1=2 & 1 > 3
    else if (SuperTotal [0] == SuperTotal [1] && SuperTotal [0] > SuperTotal [2])
    {
        System.out.println ("2First: " + name [0] + ", " + name [1] + "\nSecond: " + name [2]);
    }
    //2=3 & 2 > 1
    else if (SuperTotal [1] == SuperTotal [2] && SuperTotal [1] > SuperTotal [0])
    {
        System.out.println ("3First: " + name [1] + ", " + name [2] + "\nSecond: " + name [0]);
    }
    //1=3 & 1 > 2
    else if (SuperTotal [0] == SuperTotal [2] && SuperTotal [0] > SuperTotal [1])
    {
        System.out.println ("4First: " + name [0] + ", " + name [2] + "\nSecond: " + name [1]);
    }
    //1=2 & 1 < 3
    else if (SuperTotal [0] == SuperTotal [1] && SuperTotal [0] < SuperTotal [2])
    {
        System.out.println ("5First: " + name [2] + "'nSecond: " + name [0] + ", " + name [1]);
    }
    //1=3 & 1 < 2
    else if (SuperTotal [0] == SuperTotal [2] && SuperTotal [0] < SuperTotal [1])
    {
        System.out.println ("7First: " + name [0] + "\nSecond: " + name [1] + ", " + name [2]);
    }
    //2=3 & 2 < 1
    else if (SuperTotal [1] == SuperTotal [2] && SuperTotal [1] < SuperTotal [0])
    {
        System.out.println ("7First: " + name [0] + "\nSecond: " + name [1] + ", " + name [2]);
    }
    else if (SuperTotal [0] > SuperTotal [1] && SuperTotal [0] > SuperTotal [2] && (SuperTotal [1] < SuperTotal [2] || SuperTotal [1] > SuperTotal [2]))
    {
    }

所以基本上由于某些原因,即使给出了应该使用不同“if”语句的不同数字,它也默认为2 = 3&amp; 2&lt; 1.

你看到我做错了什么,或者任何可以更有效率的事情吗?

1 个答案:

答案 0 :(得分:0)

表示// 1 = 3&amp; 1&lt; 2输出名称错误

else if (SuperTotal [0] == SuperTotal [2] && SuperTotal [0] < SuperTotal [1])
{
    System.out.println ("7First: " + name [1] + "\nSecond: " + name [0] + ", " + name [2]);
}