InterviewSolution
| 1. |
Write a program in Java to find out week day name using switch statement. The user enters the day number and the program returns the dayname. |
|
Answer» n:-WRITE a program in Java to find out week day name using switch STATEMENT. The user enters the day number and the program returns the day name.Program:-import java.util.*;class Day{public static void main(String args[]) {Scanner sc=new Scanner(System.in);System.out.println("Enter day number: ") ;int x=sc.nextInt() ;switch(x){case 1:System.out.println("Sunday. ") ;break;case 2:System.out.println("MONDAY. ") ;break;case 3:System.out.println("Tuesday.") ;break;case 4:System.out.println("Wednesday.") ;break;case 5:System.out.println("Thursday.") ;break;case 6:System.out.println("Friday.") ;break;case 7:System.out.println("Saturday.") ;break;DEFAULT:System.out.println("Invalid choice. Please TRY again later. ") ;}}} |
|