程序产生错误的输出

时间:2016-06-04 10:06:28

标签: java

以下程序遇到问题。我现在基本上是Java新手。

代码如下所示:

public class IfElseIf{

     public static void main(String []args)
     {
        int date=26;
        int month=9;
        int year=1995;
        if ((date>=1 | date <=10) || (month>=1 | month <=4) || year==1995)
        {
            System.out.println("Your bday is in between 1-10/1-4/1995");        

        }
        else if((date>=11 | date <=20) || (month >=5 | month <=8) || year==1995)
        {
            System.out.println("Your bday is in between 11-20/5-8/1995");
        } 
        else if((date>=21 | date<=31) || (month >=9 | month <=12) || year==1995)
        {
            System.out.println("Your bday is in between 21-31/9-12/1995");
        }
        else
        {
            System.out.println("Your bday not found");
        }
     }
}

在运行上面的内容时,它给出了以下输出:

Your bday is in between 1-10/1-4/1995

这里可能有什么问题?

1 个答案:

答案 0 :(得分:1)

您使用了错误的操作符; |是按位&#34;或&#34;,您想要逻辑&#34; AND&#34;,即&&