Computer Science, asked by Atlas99, 1 day ago

Write a program to accept a number as parameter and display corresponding day of a week.​

Answers

Answered by anindyaadhikari13
9

\textsf{\large{\underline{Solution}:}}

The given problem is solved using language - Java.

public class Java{

   public static void main(int n){

       try{

           String arr[]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};

           System.out.println("You entered: "+n);

           System.out.println("Day: "+arr[n-1]);

       }

       catch(Exception e){

           System.out.println("Invalid Input.");

       }

   }

}

\textsf{\large{\underline{Logic}:}}

  • The days are stored in an array. Then the required date is accessed when input is taken from the user. For invalid input, ArrayIndexOutOfBoundsException is thrown. In that case, an appropriate message is displayed.

See attachment for output.

Attachments:

anindyaadhikari13: Thanks for the brainliest :)
Answered by Missincridedible
1

‌\boxed{\fcolorbox{black}{red}{◕ᴗ◕ Missincridedible Here◕ᴗ◕}}

Attachments:
Similar questions