I'm pretty new to Java, and coding in general. In my class we need the user to input the month (1-12) and a day (1-30) and we determine on a set date (june 15 to sept 30th) if it is or is not monsoon season. I'm trying to use a if else statement in a switch to say that anytime before june 15 is not monsoon season but my code keeps showing both if and else statement. Any help is welcomed, thank you!
import java.util.*;
public class Monsoon
{ public static void main (String[]args)
{
Scanner kb = new Scanner (System.in);
// Prompt the user to enter month & Day
System.out.print("Please enter a month(1-12) and day (1-31): " );
int month = kb.nextInt();
int day = kb.nextInt();
// using a switch statement to show months
switch (month){
case 1:
System.out.println("is NOT monsoon season");
break;
case 2:
System.out.println("is NOT monsoon season");
break;
case 3:
System.out.println("is NOT monsoon season");
break;
case 4:
System.out.println("is NOT monsoon season");
break;
case 5:
System.out.println("is NOT monsoon season");
break;
case 6:
System.out.println("“is monsoon season");
// use if else statement so user knows that before june 15 is not monsoon season
if (day>=15)
System.out.print("it is monsoon season");
else
System.out.print("it is not monsoon season");
break;
case 7:
System.out.println("“is monsoon season");
break;
case 8:
System.out.println("“is monsoon season");
break;
case 9:
System.out.println("“is monsoon season");
break;
case 10:
System.out.println("is NOT monsoon season");
break;
case 11:
System.out.println("is NOT monsoon season");
break;
case 12:
System.out.println("is NOT monsoon season");
break;
default: System.out.println("not valid");
break;
}
}
}
Aucun commentaire:
Enregistrer un commentaire