Write a program to accept a number as parameter and display corresponding day of a week.
Answers
Answered by
9
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.");
}
}
}
- 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
1
Attachments:
Similar questions