Hey. I'm taking an intro to java programming course, and it's pretty interesting. I've run into something weird. I just need a check if my logic is okay.
So first I state that "if day1 is greater than 1 and less than 17th, then print out January day1 is Winter Recess!"
Then when I say "else if day1 is less than 31, then January day1 is not a school holiday," is my code a logical error? I ask because the numbers in the first statement are also less than 31.
The output comes out correctly, so I'm just wondering.
output:
"January 17 is Winter Recess!
BUILD SUCCESSFUL (total time: 6 seconds)"
So first I state that "if day1 is greater than 1 and less than 17th, then print out January day1 is Winter Recess!"
Then when I say "else if day1 is less than 31, then January day1 is not a school holiday," is my code a logical error? I ask because the numbers in the first statement are also less than 31.
The output comes out correctly, so I'm just wondering.
output:
"January 17 is Winter Recess!
BUILD SUCCESSFUL (total time: 6 seconds)"
Code:
switch ( month1 ) {
case 1:
if ( (day1 >= 1) && (day1 <= 17) )
System.out.println( "January " + (day1) +
" is Winter Recess!");
else if (day1 == 19)
System.out.println( "January " + (day1) +
" is Martin Luther King's Birthday." );
else if (day1 <= 31)
System.out.println( "January " + (day1) +
" is not a school holiday." );
else
System.out.println( "You entered an invalid date. " +
"Please try again.");