To create a Java program to find the number of days in a month
- Import the Scanner class from the java.util package.
- Define a public class named "Main".
- Declare the main method with the signature "public static void main(String[] args)".
- Inside the main method, create an instance of the Scanner class using "Scanner sc = new Scanner(System.in)" to read input from the user.
- Declare an integer variable "month" to store the user's input.
- Use conditional statements (if-else) to determine the number of days in the entered month
- End the program
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int month;
System.out.println("Enter month number from 1(-Jan) to 12(-Dec): ");
month=sc.nextInt();
if(month==1||month==3||month==5||month==7||month==8||month==10||month==12){
System.out.println("31 Days in this Month");
}
else if(month==4||month==6||month==7||month==11){
System.out.println("30 Days in this Month");
}
else if(month==2){
System.out.println("28 Days in this Month");
}
else{
System.out.println("Enter a valid number from 1 to 12");
}
}
}
![image](https://private-user-images.githubusercontent.com/93427376/238111005-456fdaa0-c77b-4a37-aa7f-af69730f5948.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjIxNjI4MjQsIm5iZiI6MTcyMjE2MjUyNCwicGF0aCI6Ii85MzQyNzM3Ni8yMzgxMTEwMDUtNDU2ZmRhYTAtYzc3Yi00YTM3LWFhN2YtYWY2OTczMGY1OTQ4LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MjglMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNzI4VDEwMjg0NFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWMyMzNmY2Y4YzNhOTAwNGQyMzZlMjMyYTExMzAyNjQ5MmJhOTI5MGQzY2E2ZWFjYjY4MjkxNTM5YWYwZDYyZmYmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.sj1rgHRH6La2k1Z21ngMbYmv9RHvCrNYcBoGwarEihE)
Hence the number of days in a month are determined using Java Programming language.