Answers for "switch java"

81

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
78

javascript switch

//javascript multiple case switch statement
var color = "yellow";
var darkOrLight="";
switch(color) {
    case "yellow":case "pink":case "orange":
        darkOrLight = "Light";
        break;
    case "blue":case "purple":case "brown":
        darkOrLight = "Dark";
        break;
    default:
        darkOrLight = "Unknown";
}

//darkOrLight="Light"
Posted by: Guest on July-31-2019
8

set java

import java.util.*;
public class SetDemo {

  public static void main(String args[]) { 
      int count[] = {34, 22,10,60,30,22};
      Set<Integer> set = new HashSet<Integer>();
      try {
         for(int i = 0; i < 5; i++) {
            set.add(count[i]);
         }
         System.out.println(set);

         TreeSet sortedSet = new TreeSet<Integer>(set);
         System.out.println("The sorted list is:");
         System.out.println(sortedSet);

         System.out.println("The First element of the set is: "+ (Integer)sortedSet.first());
         System.out.println("The last element of the set is: "+ (Integer)sortedSet.last());
      }
      catch(Exception e) {}
   }
} 

OUTPUT:

              [34, 22, 10, 60, 30]
              The sorted list is:
              [10, 22, 30, 34, 60]
              The First element of the set is: 10
              The last element of the set is: 60
Posted by: Guest on May-31-2020
7

break java

//Conclusion
        break == jump out side the loop
        continue == next loop cycle
        return == return the method/end the method.
          
  for(int i = 0; i < 5; i++) {
      System.out.println(i +"");
      if(i == 3){
        break;
        
      }
    }
  System.out.println("finish!");
/* Output
0
1
2
3
finish!
*/
Posted by: Guest on November-13-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
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

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language