java - BlueJ Java 复合条件

标签 java conditional-statements bluej compound-assignment

我目前正在编写一些代码,但遇到了问题,无法理解它。我对此很陌生,如有任何帮助,将不胜感激

我正在尝试为日期创建一个复合条件,但似乎无法理解如何做到这一点。

public void rentBook(int theBorrowerNumber, String theReturnDate)
{

        if(theBorrowerNumber <=0)                                         // checks if the borrower number is less or equal to 0
        {
            System.out.println("Invalid borrower number");                // prints the error message
        }
    ///////////////////////////////////////
    returnDate = theReturnDate;                                           // reDate aquires theReDate content
    String day = returnDate.substring(0,2);                               // set the day to the first 2 numbers from the date
    String month = returnDate.substring(2,4);                             // set the month to the second 2 numbers form the date
    int theDay = Integer.parseInt(day);                                   // converts the day string to integer
    int theMonth = Integer.parseInt(month);                               // converts the month string to integer
    //////////////////////////////////////  
        if(theDay <= 0 | theDay >= 32 | theMonth <= 0 | theMonth >= 13)   //setting the parameters the date must be within
        {
            System.out.println("Invalid date");                           // prints out if the date is wrong
        }
        else
        {
            super.setBorrowerNumber(theBorrowerNumber);                  // sets the borrower number in the super class
        }

}   

最佳答案

逻辑或运算符是 || 而不是 |

if(theDay <= 0 || theDay >= 32 || theMonth <= 0 || theMonth >= 13)   

关于java - BlueJ Java 复合条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20647955/

相关文章:

java - Rest方法没有得到正确的数据

java - 按钮状态 - 按下和重新按下

java - struts 2中的文件下载问题

css - 合并 CSS IE 调用

php - 生成两个随机数第一个数字小于第二个php

java - 如何删除包含Java中其他文件夹的文件夹?

java - 按姓氏和顺序对行进行排序

java - 无法找到两个链表的两种迭代类型之间的区别

mysql - 有条件地添加/删除列 MySQL

java - boolean if 语句