Java Program Of Break Statement With While Loop

01. Example:

import java.util.Scanner;

class breakStatementWithWhileLoop {
  public static void main(String[] args) {
      
    int N;
    Scanner input = new Scanner(System.in);
    
    while (true) {
      System.out.print("Input An Integer: ");
      N = input.nextInt();
      if (N == 0) {
        System.out.println("nYou Entered: 0");
        break;
      }
      System.out.println("nYou Entered " + N);
    }
    
  }
}

Output:

Input An Integer: 10
You Entered 10
Input An Integer: 20
You Entered 20
Input An Integer: 30
You Entered 30
Input An Integer: 40
You Entered 40
Input An Integer: 0
You Entered: 0

Leave a comment