Question
import java.util.Scanner; public class DaysInMonth{ public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println(Enter month from 1-12: ); int month= sc.nextInt(); System.out.println(Enter
import java.util.Scanner; public class DaysInMonth{ public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("Enter month from 1-12: "); int month= sc.nextInt(); System.out.println("Enter year: "); int year = sc.nextInt(); int m=sc.nextInt(); System.out.println(month + "/" + year + " has " + m + " days"); switch (m) { case 1: m = 31; break; case 2: if (isLeap(year)) m = 29; else m= 28; break; case 3: m = 31; break; case 4: m = 30; break; case 5: m = 31; break; case 6: m= 30; break; case 7: m = 31; break; case 8: m = 31; break; case 9: m= 30; break; case 10: m = 31; break; case 11: m = 30; break; case 12: m = 31; break; } } private static boolean isLeap(int year) { boolean leap = false; if (year % 4 == 0) { if (year % 100 == 0) { if (year % 400 == 0) leap = true; else leap = false; } else leap = true; } else leap = false; return leap; } }
Why I only can print the enter years and month but is not print the System.out.println(month + "/" + year + " has " + m + " days"); which is not print the result
javac DaysInMonth.java >Exit code: 0 >java DaysInMonth Enter month from 1-12: 10 Enter year: 2020 Its not print the result" v:shapes="Picture_x0020_87">
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started