-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlesson_11.java
More file actions
56 lines (43 loc) · 1.5 KB
/
Copy pathlesson_11.java
File metadata and controls
56 lines (43 loc) · 1.5 KB
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
/*_______________________________*/
//! Break and Continue Statements!!
package Notes;
import java.util.Scanner;
public class lesson_11 {
public static void main(String[] args){
Scanner input = new Scanner(System.in);
int counter=1,num,sum=0;
while(counter<=7){
System.out.print("Enter the number "+counter+" : ");
num = input.nextInt();
if(num<0){
System.out.println("Negative Number are not allowed!");
break;
}
sum+=num;
counter++;
}
System.out.println("Sum = "+sum);
int num1=0, count=1,sum1=0;
while(count<=5){
System.out.print("Enter a positive number "+count+" : ");
num1=input.nextInt();
if(num1<0){
System.out.println("Negative numbers are not allowed");
continue;
}
sum1+=num1;
count++;
}
System.out.println("Sum = "+sum1);
input.close();
}
}
/*_______________________________*/
//! The break statement
//? The break statement is typically used to exit early from a loop (for,while,do..while)
//? After the break statement, the remaining of the statements inside the loop are skipped. Then, execution continues starting at the first statement after the loop
/*_______________________________*/
//! The continue statement
//? The continue statement may be used in all loop statements (for,while,do..while)
//? The continue statement skips the remaining statement inside the loop; and proceeds with the next iteration, if any.
/*_______________________________*/