Java Online Compiler
Example: Java program of decision making by using the java switch case statement
C
C++
C#
Java
Python
PHP
Main.java
STDIN
Run
// Java program of decision making by using the java switch case statement import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.println("Enter a week number among 1 to 7\n"); int w = in.nextInt(); if (w > 0) { switch (w) { case 1: System.out.println("Hi\nIt's sunday on today, It's the week-off day.\n"); break; case 2: System.out.println("Hi\nIt's monday on today, It's the working day.\n"); break; case 3: System.out.println("Hi\nIt's tuesday on today, It's the working day.\n"); break; case 4: System.out.println("Hi\nIt's wednesday on today, It's the working day.\n"); break; case 5: System.out.println("Hi\nIt's thursday on today, It's the working day.\n"); break; case 6: System.out.println("Hi\nIt's friday on today, It's the working day.\n"); break; case 7: System.out.println("Hi\nIt's saturday on today, It's the week-off day.\n"); break; // w parameter doesn't match any case constant then It navigates to default: default: System.out.println("Sorry, You entered the wrong week number, Kindly try again\n"); } } else { System.out.println("Sorry didn't entered any week number!\n"); } } }
3
Output
Clear
ADVERTISEMENTS