-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBreakWhileLoop.java
More file actions
27 lines (24 loc) · 852 Bytes
/
BreakWhileLoop.java
File metadata and controls
27 lines (24 loc) · 852 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
import java.util.Scanner;
/**
* 17.While loop using break Program in java
*/
public class BreakWhileLoop {
public static void main(String[] args) {
try(Scanner scan = new Scanner(System.in)) {
while (true) {
System.out.println("Enter a positive number: ");
while (!scan.hasNextInt()) {
System.out.println("Invalid input! Please enter a valid positive integer:");
scan.next();
}
int num = scan.nextInt();
if (num == 0 || num == 99 || num == 100 || num == 500 || num == 1001) {
System.out.println("Entered number matched!");
break;
}
}
} catch (Exception e) {
System.out.println("Unexpected Error! Please try again. !!!");
}
}
}