集册 Java实例教程 使用do验证来自用户的输入

使用do验证来自用户的输入

欢马劈雪     最近更新时间:2020-01-02 10:19:05

560
使用do-while循环验证来自用户的输入
//时 代 J a v a - nowjava.com 提 供

import java.util.Scanner;


public class Main {

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


   public static void main(String[] args) {

      int bank = 1000;   // assume the user has $1,000

      int bet;           // the bet entered by the user


      System.out.println("You can bet between 1 and " +

          bank);

      do

      {

          System.out.print("Enter your bet: ");

          bet = sc.nextInt();

      } while (
展开阅读全文