ошибка: неверные типы операндов для двоичного оператора '&&' первого типа int и второго типа логического типа - PullRequest
0 голосов
/ 25 сентября 2019

Я новичок в Java, и мне очень нравится этот новый опыт обучения.Мне поручили задание, в котором мы должны создать простой календарь, в котором пользователю нужно указать дату, а программа должна сообщить вам, является ли она правильной.

Однако я получаю код ошибки, который имиспользуя неверный тип операнда.Я не могу использовать int с логическим типом.Однако мне кажется, что я не могу найти проблему.

Любая помощь и понимание приветствуются

public static void main(String[] args) {

    Scanner userInput = new Scanner(System.in);  // Creating the new Scanner

    System.out.print("Choose a day: ");            //Asking for user to introduce a day
    int day = userInput.nextInt();

    System.out.print("Choose a month: ");           // Asking user to introduce a month
    int month  = userInput.nextInt(); 

    System.out.print("Choose a year: ");            //Asking user to introduce a year
    int year  = userInput.nextInt(); 


    if ( (1<= day <= 31) && (1 <= month <= 12) && (year >= 0)){     //marking the limits of day, month and year
        System.out.println(" Congratulations, the date you introduced : " + day + month + year +"exists!!");
    } else if ( (day > 30) && (month = 2 || 4 || 6 || 9 || 10) && (year >= 0)){             //marking the months wich have 30 days
        System.out.println(" Oh no, the date you introduced : " + day + month + year +" does Not exists!! You can always try again");
    }else if ( (day > 28) && (month = 2) && (year >=0)){                //marking month February
       System.out.println(" Oh no, the date you introduced : " + day + month + year +" does Not exists!! You can always try again");
    } else {
        System.out.println(" Oh no, the date you introduced : " + day + month + year +" does Not exists!! You can always try again");
    }

}

1 Ответ

0 голосов
/ 25 сентября 2019

Вы должны использовать if ( (day >= 1 && day <= 31) && (month >= 1 && month <= 12) && (year >= 0)) Также за каждый месяц нужно ставить month == 2 || month == 4 ...

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...