uses a do-while loop to get this input from the user : While « Language Basics « Java






uses a do-while loop to get this input from the user

 

import java.util.Scanner;

public class MainClass {

  static Scanner sc = new Scanner(System.in);

  public static void main(String[] args) {
    int bank = 1000;
    int bet;

    do {
      System.out.print("Enter your bet: ");
      bet = sc.nextInt();
    } while ((bet <= 0) || (bet > bank));
  }
}

 








Related examples in the same category

1.while Demowhile Demo
2.Do While DemoDo While Demo
3.Demonstrates the while loop.Demonstrates the while loop.
4.Do WhileDo While
5.Java labeled while loop.Java labeled while loop.