-
Notifications
You must be signed in to change notification settings - Fork 0
/
Loop_Ctrl_Stmnt.java
56 lines (46 loc) · 1.1 KB
/
Loop_Ctrl_Stmnt.java
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
48
49
50
51
52
53
54
55
56
import java.util.Scanner;
public class Loop_Ctrl_Stmnt {
/*
* jump statements -> break,continue;
*/
public static void main(String[] args) {
for(int i = 1;i <= 10; i++) {
if(i == 7)
continue;
System.out.println(i);
}
int n;
System.out.println("enter num ");
Scanner scanner = new Scanner(System.in);
n = scanner.nextInt();
while(n >= 0) {
if(n % 10 == 0) {
System.out.println(n);
break;
}
n--;
}
//find sum of all given num
double m,sum = 0;
System.out.println("enter numbers and enter -ve num to stop the loop: \n");
Scanner scanner1 = new Scanner(System.in);
while(true) {
m = scanner1.nextDouble();
if(m < 0.0) {
break;
}
sum += m;
}
System.out.println(sum + "\n");
outerLoop: //labels
for(int i =1; i <=5; i++) {
innerLoop:
for(int j =1; j <= 5; j++) {
if(i ==3 && j ==3)
break innerLoop; //labelled loop -->alernate for goto in the other languages
System.out.print(j);
}
System.out.println("\n");
}
}
}