Advertisement
binibiningtinamoran

Months

Oct 30th, 2019
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.90 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Months {
  4.  
  5.     public static void main(String[] args) {
  6.  
  7.         String[] months = new String[] {"January", "February", "March", "April",
  8.                 "May", "June", "july", "August",
  9.                 "September", "October", "November", "December"};
  10.  
  11.         Scanner scan = new Scanner(System.in);
  12.         int number;
  13.         String yesOrNo;
  14.         do {
  15.             System.out.print("\nEnter a number: ");
  16.             number = scan.nextInt();
  17.  
  18.             if (number >= 1 && (number <= months.length)) {
  19.                 System.out.printf("Month %d is \"%s\".\n", number,months[number - 1]);
  20.             } else {
  21.                 System.out.println("Invalid input detected.");
  22.             }
  23.  
  24.             System.out.println("Do you want to continue (y or n)? ");
  25.             yesOrNo = scan.next();
  26.  
  27.         } while (yesOrNo.equalsIgnoreCase("y"));
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement