Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Christopher Clemente
- //Comp 171-002
- //Homework #3
- import java.util.Scanner;
- public class clas {
- public static void main(String[] args) {
- Scanner keyboard = new Scanner(System.in);
- int days = 0;
- System.out.println("Please enter a month and year to find out how many days are in that month.");
- System.out.print("Please enter a month (1-12) : ");
- int month = keyboard.nextInt();
- System.out.print("Please enter a year : ");
- int year = keyboard.nextInt();
- String mnth = null;
- switch(month){
- case 1: mnth = "Janurary"; break;
- case 2: mnth = "Feburary"; break;
- case 3: mnth = "March"; break;
- case 4: mnth = "April"; break;
- case 5: mnth = "May"; break;
- case 6: mnth = "June"; break;
- case 7: mnth = "July"; break;
- case 8: mnth = "August"; break;
- case 9: mnth = "September"; break;
- case 10: mnth = "October"; break;
- case 11: mnth = "November"; break;
- case 12: mnth = "December"; break;
- }
- if(month == 2){
- if ((year % 4) == 0){
- days = 29;
- }
- else{
- days = 28;
- }
- }
- else if(month % 2 == 0){
- days = 30;
- }
- else{
- days = 31;
- }
- System.out.println("There are " + days + " days in " + mnth);
- }
- }
- /*
- Please enter a month and year to find out how many days are in that month.
- Please enter a month (1-12) : 2
- Please enter a year : 12
- There are 29 days in Feburary
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement