Hello,
I am new to the forum and to Java have no programming experience. try to write a program that enters a year and month as integers and displays the number of days in the month.
here is what I have written any help would be much appericated.
import java.util.Scanner;
public class Program3
{
public static void main(String [] args) {
Scanner input = new Scanner (System.in);
//Enter a Month 1-12
System.out.print("Enter a Monthname: ");
int Monthname = input.nextInt();
//Enter a day 1-31
System.out.print ("Enter a Monthday: " );
int Monthday = input.nextInt();
//Enter a Year
System.out.print ("Enter a Year: ");
int Year = input.nextInt();
switch (Monthname) {
case 1: Monthname = "January";
Monthday = "31";
break;
case 2: Monthname = "February"; Monthday =(Year % 4 == 0 && Year % 100 != 0) || (Year % 400 == 0)? 28 : 29;
break;
case 3: Monthname = "March";
Monthday = "31"; break;
case 4: Monthname = "April"; Monthday = "30"; break;
case 5: Monthname = "May"; Monthday = "31"; break;
case 6: Monthname = "June"; Monthday = "30";
break;
case 7: Monthname = "July"; Monthday = "31";
break;
case 8: Monthname = "August";
Monthday = "31"; break;
case 9: Monthname = "September"; Monthday = "30";
break;
case 10: Monthname = "October";
Monthday = "31"; break;
case 11: Monthname = "November"; Monthday = "30";
break;
case 12: Monthname = "December";
Monthday = "31"; break;
default: System.out.println ("Errors: invalid data");
System.exit(0);
}
//Display results
System.out.println("Monthname + Year" + "has" + Monthday + "days");
}
}
this is what I wrote any help in correcting the incompatible types for the case.
I am using JCreator
Thanks/