Advertisement
RazorBlade57

Untitled

Oct 4th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1.  
  2. //Christopher Clemente
  3. //Comp 171-002
  4. //Homework #3
  5.  
  6.  
  7. import java.util.Scanner;
  8. public class clas {
  9.  
  10. public static void main(String[] args) {
  11.  
  12. Scanner keyboard = new Scanner(System.in);
  13.  
  14. int days = 0;
  15.  
  16. System.out.println("Please enter a month and year to find out how many days are in that month.");
  17.  
  18. System.out.print("Please enter a month (1-12) : ");
  19. int month = keyboard.nextInt();
  20.  
  21. System.out.print("Please enter a year : ");
  22. int year = keyboard.nextInt();
  23.  
  24. String mnth = null;
  25.  
  26. switch(month){
  27. case 1: mnth = "Janurary"; break;
  28. case 2: mnth = "Feburary"; break;
  29. case 3: mnth = "March"; break;
  30. case 4: mnth = "April"; break;
  31. case 5: mnth = "May"; break;
  32. case 6: mnth = "June"; break;
  33. case 7: mnth = "July"; break;
  34. case 8: mnth = "August"; break;
  35. case 9: mnth = "September"; break;
  36. case 10: mnth = "October"; break;
  37. case 11: mnth = "November"; break;
  38. case 12: mnth = "December"; break;
  39. }
  40.  
  41. if(month == 2){
  42. if ((year % 4) == 0){
  43. days = 29;
  44.  
  45. }
  46. else{
  47. days = 28;
  48. }
  49. }
  50.  
  51. else if(month % 2 == 0){
  52. days = 30;
  53. }
  54. else{
  55. days = 31;
  56.  
  57. }
  58. System.out.println("There are " + days + " days in " + mnth);
  59. }
  60. }
  61.  
  62.  
  63. /*
  64. Please enter a month and year to find out how many days are in that month.
  65. Please enter a month (1-12) : 2
  66. Please enter a year : 12
  67. There are 29 days in Feburary
  68. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement