Introduction
In this demo I have used NetBeans IDE 8.2 for debugging purpose. But you can use any java programming language compiler as per your availability..
In this demo I have used NetBeans IDE 8.2 for debugging purpose. But you can use any java programming language compiler as per your availability..
import java.util.Scanner;
public class JavaExcercise {
public static void main(String[] strings) {
Scanner input = new Scanner(System.in);
int numberOfDaysInMonth = 0;
String MonthName = "Unknown";
System.out.print("Input a month number: ");
int month = input.nextInt();
System.out.print("Input a year: ");
int year = input.nextInt();
switch (month) {
case 1:
MonthName = "January";
numberOfDaysInMonth = 31;
break;
case 2:
MonthName = "February";
if ((year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0))) {
numberOfDaysInMonth = 29;
} else {
numberOfDaysInMonth = 28;
}
break;
case 3:
MonthName = "March";
numberOfDaysInMonth = 31;
break;
case 4:
MonthName = "April";
numberOfDaysInMonth = 30;
break;
case 5:
MonthName = "May";
numberOfDaysInMonth = 31;
break;
case 6:
MonthName = "June";
numberOfDaysInMonth = 30;
break;
case 7:
MonthName = "July";
numberOfDaysInMonth = 31;
break;
case 8:
MonthName = "August";
numberOfDaysInMonth = 31;
break;
case 9:
MonthName = "September";
numberOfDaysInMonth = 30;
break;
case 10:
MonthName = "October";
numberOfDaysInMonth = 31;
break;
case 11:
MonthName = "November";
numberOfDaysInMonth = 30;
break;
case 12:
MonthName = "December";
numberOfDaysInMonth = 31;
}
System.out.print(MonthName + " " + year + " has " + numberOfDaysInMonth + " days\n");
}
}
Introduction : java final keyword The final keyword present in Java programming language is generally used for restricting the user. …
C++ Memory Management We know that arrays store contiguous and the same type of memory blocks, so memory is allocated …