I am trying to implement a date system that inevitably displays tomorrows day, month and year.
The problem I am having is that the one of the if statements always returns true, and the ones after this one always return false.
Here is part of my code:
public class dateVerification {
int tomorrowDay = 0;
int tomorrowMonth = 0;
int tomorrowYear = 0;
int day = 0;
int month = 0;
int year = 0;
public void date() {
Scanner myScanner = new Scanner(System.in);
System.out.println("Enter the day");
day = myScanner.nextInt();
System.out.println("Enter the month");
month = myScanner.nextInt();
System.out.println("Enter the year");
year = myScanner.nextInt();
switch (month) {
case 1:
if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10) {
if (day < 31) {
tomorrowDay = day + 1;
} else {
tomorrowDay = 1;
tomorrowMonth = month + 1;
}
}
break;
The line that is returning true is:
if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10)
And everything else is returning false, i.e. my case 2 statement
if (month == 4 || month == 6 || month == 9 || month == 11)
Can anybody shed some light on this?
You are testing the month
field.
In case 1 the month is always 1.
switch (month) {
case 1: //mount = 1 !!
if (month == 1 ||...
//
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments