Answers for "java switch"

80

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
4

switch statement in java

// switch case in java example programs
public class SwitchStatementExample
{
   public static void main(String[] args)
   {
      char grade = 'A';
      switch(grade) {
          case 'A' :
              System.out.println("Distinction.");
              break;
          case 'B' :
          case 'C' :
              System.out.println("First class.");
              break;
          case 'D' :
              System.out.println("You have passed.");
          case 'F' :
              System.out.println("Fail. Try again.");
              break;
          default :
              System.out.println("Invalid grade");
      }
      System.out.println("Grade is: " + grade);
   }
}
Posted by: Guest on November-25-2020
4

java switch case

switch(x){
	case(0):		//if x == 0
    	//do some stuff
    	break;
    //add more cases
  default:			//when x does not match any case
    //do some stuff
    break;
}
Posted by: Guest on June-01-2020
1

java switch on what classes

A switch works with the byte, short, char, and int primitive data types.
It also works with enumerated types (discussed in Enum Types), the String
class, and a few special classes that wrap certain primitive types: 
Character , Byte , Short , and Integer (discussed in Numbers and Strings).
Posted by: Guest on March-07-2021
2

java switch

//the cooler looking edition (with input example)
Scanner scn = new Scanner(System.in);
int asd = scn.nextInt();

switch(asd)
{
  case 1 -> System.out.println("case 1");
  case 2 -> System.out.println("case 2");
  case 5 -> System.out.println("case 5");
  //case n...
  default -> case 1 -> System.out.println("check out tunalad.bandcamp.com");
}

/* Output:
asd = 1: "case 1"
asd = 2: "case 2"
asd = 5: "case 5"
asd = 33213: "check out tunalad.bandcamp.com"
*/
Posted by: Guest on July-10-2021
1

switch statement in java

// syntax of switch statement in java
switch(expression)
{
   case 1 value :
   // code goes here
   break;

   case 2 value :
   // code goes here
   break;

   case 3 value :
   // code goes here
   break;
   .
   .
   .
   .
   
   default: // optional
   // default code goes here
}
Posted by: Guest on November-25-2020

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language