DEV Community

.
.

Posted on

ASSIGNMENT 1 - ANSWER 2

ASSIGNMENT 1 ANSWERS

Top comments (1)

Collapse
 
amroessam profile image
amroessam

I tried to make it simpler than using multiple if functions


import java.util.Scanner;
class Main {
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);

   String [] month_name = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};

   System.out.println("Enter month number: ");
   int month = scan.nextInt();
   String monthName = month_name[month - 1];
   if(month> 12 || month<1){
    System.out.println("month is not available");
   }
   else {
     System.out.println("Month is: " + monthName);
   }
  }
}