Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Months {
- public static void main(String[] args) {
- String[] months = new String[] {"January", "February", "March", "April",
- "May", "June", "july", "August",
- "September", "October", "November", "December"};
- Scanner scan = new Scanner(System.in);
- int number;
- String yesOrNo;
- do {
- System.out.print("\nEnter a number: ");
- number = scan.nextInt();
- if (number >= 1 && (number <= months.length)) {
- System.out.printf("Month %d is \"%s\".\n", number,months[number - 1]);
- } else {
- System.out.println("Invalid input detected.");
- }
- System.out.println("Do you want to continue (y or n)? ");
- yesOrNo = scan.next();
- } while (yesOrNo.equalsIgnoreCase("y"));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement