Conditional operator practice 5 in JAVA. Write a Java program that keeps a number from the user and generates an integer between 1 and 7 and displays the name of the weekday.

Write a Java program that keeps a number from the user and generates an integer between 1 and 7 and displays the name of the weekday.


Solution: 


 
package w3;

import java.util.Scanner;

public class ex5 {
    public static void main(String[] args) {
        Scanner pass = new Scanner(System.in);
       
    int x;
   
        System.out.print("Enter Any Number : ");
        x=pass.nextInt();
       
    switch(x){
            case 1:
                System.out.println("Saturday");
                break;
            case 2:
                System.out.println("Sunday");
                break;
            case 3:
                System.out.println("Monday");
                break;
            case 4:
                System.out.println("Tuesday");
                break;
            case 5:
                System.out.println("Wednesday");
                break;
            case 6:
                System.out.println("Thusday");
                break;
            case 7:
                System.out.println("Friday");
                break;
               
            default:
                System.out.println("This is not weekday");
    }
   
    }
   
}








Comments