Question: Write this code in pseudocode import java.util.Scanner; public class Exercise { public static void main ( String [ ] args ) { Scanner input =

Write this code in pseudocode
import java.util.Scanner;
public class Exercise {
public static void main(String[] args){
Scanner input = new Scanner(System.in);
System.out.print("Enter a month in the year (e.g.,1 for Jan): ");
int month = input.nextInt();
System.out.print("Enter a year: ");
int year = input.nextInt();
input.close();
int days = getDaysInMonth(month, year);
if (days !=-1){
String monthName = getMonthName(month);
System.out.println(monthName +""+ year +" has "+ days +" days.");
} else {
System.out.println("Invalid month number. Please enter a number between 1 and 12.");
}
}
public static int getDaysInMonth(int month, int year){
if (month <1|| month >12){
return -1; // Invalid month
}
switch (month){
case 2:
if ((year %4==0 && year %100!=0)||(year %400==0)){
return 29; // Leap year
} else {
return 28; // Non-leap year
}
case 4: case 6: case 9: case 11:
return 30; // April, June, September, November
default:
return 31; // January, March, May, July, August, October, December
}
}
public static String getMonthName(int month){
String[] monthNames ={
"January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"
};
return monthNames[month -1];
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!