集册 Java实例教程 当用户输入错误的输入时显示错误消息

当用户输入错误的输入时显示错误消息

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

455
当用户输入错误的输入时显示错误消息

import java.util.Scanner;
/**
 from
* nowjava.com 
**/


public class Main {


   public static void main(String[] args) {

      int bank = 1000;   

      int bet;           // the bet entered by the user


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

      Scanner sc = new Scanner(System.in);

      do {

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

          bet = sc.nextInt();


          if ( (bet <= 0) || (bet > bank) )// 来 自 n o w j a v a . c o m - 时代Jav
展开阅读全文