Java Program - Find The Number Of Days In A Month Of The Year [JAVA EXERCISE WITH SOLUTION]
Coding River
Java program - Find The Number Of Days In A Month Of The Year [JAVA EXERCISE WITH SOLUTION]
This is going to be Java program to find the number of days in a month. The user will input an integer number from 1 to 12 corresponding to each month of the year. He will also have to input the year
import java.util.Scanner;
public class TestApp {
public static void main(String[] args){
Scanner console = new Scanner(System.in);
int number_of_month, year; int nbre_of_daysinmonth = 0; String month= "Not exist";
System.out.println("What is the number of the month ?"); number_of_month = console.nextInt();
System.out.println("Enter the year"); year = console.nextInt();
switch(number_of_month) { case 1: month = "January"; nbre_of_daysinmonth = 31; break;
case 2: month = "February"; if ((year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0))) { nbre_of_daysinmonth = 29; } else { nbre_of_daysinmonth = 28; } break; case 3: month = "March"; nbre_of_daysinmonth = 31; break; case 4: month = "April"; nbre_of_daysinmonth = 30; break; case 5: month = "May"; nbre_of_daysinmonth = 31; break; case 6: month = "June"; nbre_of_daysinmonth = 30; break; case 7: month = "July"; nbre_of_daysinmonth = 31; break; case 8: month = "August"; nbre_of_daysinmonth = 31; break; case 9: month = "September"; nbre_of_daysinmonth = 30; break; case 10: month = "October"; nbre_of_daysinmonth = 31; break; case 11: month = "November"; nbre_of_daysinmonth = 30; break; case 12: month = "December"; nbre_of_daysinmonth = 31; }
System.out.println("The month of " + month + " " + year + "has "
- nbre_of_daysinmonth); } }
I am trying to grow my channel, so if you find this video useful, please Subscribe and hit the notification bell :)
Thanks for watching and I hope you liked and learned something new!
#codingriver #startingoutinjava #javaprogrammingexerciseswithsolution ... https://www.youtube.com/watch?v=4PvHH8czmjQ
22476175 Bytes