I have the following code, but I cannot figure out how to do it. I stopped at march, but basically where the input is numbers 1-12 the code should print out the numbers corresponding month name. Ex. 1 = January, 2 = February etc. After correcting this, I have to assign whether or not the year they input is a leap year, causing ( ex. february to have 29 days ) the # of days to change.
import java.util.Scanner;
public class DaysInMonth
{
public static void main(String[]args)
{
Scanner input = new Scanner(System.in);
System.out.print("Enter the number of a month and a year: ");
int Input = input.nextInt();
if (Input=1)
System.out.print("January");
else if (Input=2)
Sytem.out.print("February");
else if (Input=3)
System.out.print("March");
}
}
Question
Alladaskill17
I have the following code, but I cannot figure out how to do it. I stopped at march, but basically where the input is numbers 1-12 the code should print out the numbers corresponding month name. Ex. 1 = January, 2 = February etc. After correcting this, I have to assign whether or not the year they input is a leap year, causing ( ex. february to have 29 days ) the # of days to change.
import java.util.Scanner; public class DaysInMonth { public static void main(String[]args) { Scanner input = new Scanner(System.in); System.out.print("Enter the number of a month and a year: "); int Input = input.nextInt(); if (Input=1) System.out.print("January"); else if (Input=2) Sytem.out.print("February"); else if (Input=3) System.out.print("March"); } }Link to comment
Share on other sites
10 answers to this question
Recommended Posts