forked from examplehub/Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBreak.java
More file actions
47 lines (43 loc) · 899 Bytes
/
Break.java
File metadata and controls
47 lines (43 loc) · 899 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package com.examplehub.basics;
public class Break {
public static void main(String[] args) {
/*
* 1 2 3 4
*/
for (int i = 1; i <= 10; ++i) {
if (i == 5) {
break;
}
System.out.print(i + " ");
}
System.out.println();
/*
* 100 99 98 97 96 95 94 93 92 91
*/
for (int i = 100; i >= 1; --i) {
if (i == 90) {
break;
}
System.out.print(i + " ");
}
System.out.println();
/*
* case 2 is executed
*/
int num = Integer.parseInt("2");
switch (num) {
case 1:
System.out.println("case 1 is executed");
break;
case 2:
System.out.println("case 2 is executed");
break;
case 3:
System.out.println("case 3 is executed");
break;
default:
System.out.println("default is executed");
break;
}
}
}