Answers for "how to use switch in java"

83

java switch

int day = 4;
switch (day) {
  case 6:
    System.out.println("Today is Saturday");
    break;
  case 7:
    System.out.println("Today is Sunday");
    break;
  default:
    System.out.println("Looking forward to the Weekend");
}
// Outputs "Looking forward to the Weekend"
Posted by: Guest on March-11-2020
0

switch method in java

//import java.util.Scanner;
System.out.println("What day is today ? ");
		System.out.println("First Letter Capital");
		String  a =scanner.nextLine();
		
		switch(a) {
		case "Sunday": System.out.println("Its Sunday");
		break;
		case "Monday": System.out.println("Its Monday");
		break;
		case "Tuesday": System.out.println("Its tuesday");
		break;
		case "Wednesday": System.out.println("Its Wednesday");
		break;
		case "Thursday": System.out.println("Its Thursday");
		break;
		case "Friday": System.out.println("Its Friday");
		break;
		case "Saturday":System.out.println("Its holiday ");
		break;
Posted by: Guest on September-10-2021
0

switch expression java

System.out.println(
        switch (day) {
            case MONDAY, FRIDAY, SUNDAY -> 6;
            case TUESDAY                -> 7;
            case THURSDAY, SATURDAY     -> 8;
            case WEDNESDAY              -> 9;
            default -> throw new IllegalStateException("Invalid day: " + day);
        }
    );
Posted by: Guest on September-30-2020
0

switch en java

switch (/*Variable*/)
{
  case /*Variable*/:
    /*Action*/;
    break;        
  default:
    /*Action*/;             
}
Posted by: Guest on February-10-2020
0

switch java

int day = 4;
switch (day) {
  case 6:
    System.out.println("Today is Saturday");
    break;
  case 7:
    System.out.println("Today is Sunday");
    break;
  default:
    System.out.println("Looking forward to the Weekend");
}
// Outputs "Looking forward to the Weekend"
Posted by: Guest on May-23-2021
-1

switch statement in while loop java

Scanner input=new Scanner(System.in);
int selection = input.nextInt();

while (selection<4)
{
   switch(selection){
        case 1:
           System.out.println("Please enter amount");
           double amount=input.nextDouble(); //object of scanner class
           break;

        case 2:
           System.out.println("Enter ID number"); 
           break;

        case 3:
           System.out.println("Enter amount to be credited");
           break;
      }
      System.out.println("1. Transfer\n2.Check balance\n3.Recharge");
      selection = input.nextInt(); // add this
 }
Posted by: Guest on May-22-2021

Code answers related to "how to use switch in java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language