1int day = 4;
2switch (day) {
3 case 6:
4 System.out.println("Today is Saturday");
5 break;
6 case 7:
7 System.out.println("Today is Sunday");
8 break;
9 default:
10 System.out.println("Looking forward to the Weekend");
11}
12// Outputs "Looking forward to the Weekend"
1//javascript multiple case switch statement
2var color = "yellow";
3var darkOrLight="";
4switch(color) {
5 case "yellow":case "pink":case "orange":
6 darkOrLight = "Light";
7 break;
8 case "blue":case "purple":case "brown":
9 darkOrLight = "Dark";
10 break;
11 default:
12 darkOrLight = "Unknown";
13}
14
15//darkOrLight="Light"
1import java.util.*;
2public class SetDemo {
3
4 public static void main(String args[]) {
5 int count[] = {34, 22,10,60,30,22};
6 Set<Integer> set = new HashSet<Integer>();
7 try {
8 for(int i = 0; i < 5; i++) {
9 set.add(count[i]);
10 }
11 System.out.println(set);
12
13 TreeSet sortedSet = new TreeSet<Integer>(set);
14 System.out.println("The sorted list is:");
15 System.out.println(sortedSet);
16
17 System.out.println("The First element of the set is: "+ (Integer)sortedSet.first());
18 System.out.println("The last element of the set is: "+ (Integer)sortedSet.last());
19 }
20 catch(Exception e) {}
21 }
22}
23
24OUTPUT:
25
26 [34, 22, 10, 60, 30]
27 The sorted list is:
28 [10, 22, 30, 34, 60]
29 The First element of the set is: 10
30 The last element of the set is: 60
1//Conclusion
2 break == jump out side the loop
3 continue == next loop cycle
4 return == return the method/end the method.
5
6 for(int i = 0; i < 5; i++) {
7 System.out.println(i +"");
8 if(i == 3){
9 break;
10
11 }
12 }
13 System.out.println("finish!");
14/* Output
150
161
172
183
19finish!
20*/
1// switch case in java example programs
2public class SwitchStatementExample
3{
4 public static void main(String[] args)
5 {
6 char grade = 'A';
7 switch(grade) {
8 case 'A' :
9 System.out.println("Distinction.");
10 break;
11 case 'B' :
12 case 'C' :
13 System.out.println("First class.");
14 break;
15 case 'D' :
16 System.out.println("You have passed.");
17 case 'F' :
18 System.out.println("Fail. Try again.");
19 break;
20 default :
21 System.out.println("Invalid grade");
22 }
23 System.out.println("Grade is: " + grade);
24 }
25}
1int day = 4;
2switch (day) {
3 case 6:
4 System.out.println("Today is Saturday");
5 break;
6 case 7:
7 System.out.println("Today is Sunday");
8 break;
9 default:
10 System.out.println("Looking forward to the Weekend");
11}
12// Outputs "Looking forward to the Weekend"
13