zoukankan      html  css  js  c++  java
  • Java实现1到100之间的猜数字游戏(及异常处理)

    public class Homework21 {
     public static void main(String[] args) {
      Random rand = new Random();
      Scanner sc = new Scanner(System.in);
      int num = rand.nextInt(100) + 1;
      int t = 0;
      while (true) {
       System.out.println("请输入1-100之间的整数:");
       try {
        t = sc.nextInt();
       } catch (InputMismatchException e) {
        System.out.println("输入有误!请重新输入");
        sc.next();
        continue;
       }
       if (t < num) {
        System.out.println("太小了!");
       } else if (t > num) {
        System.out.println("太大了!");
       } else {
        System.out.println("恭喜你,答对了!");
        break;
       }
      }
     }
    }
  • 相关阅读:
    比SRCNN效果好的传统超分辨率算法汇总
    CSS3 2D转换
    CSS3 文本效果
    CSS3 Gradients(渐变)
    CSS3 背景
    CSS3 圆角
    CSS3 边框
    CSS3 简介
    CSS 属性选择器
    CSS 媒体类型
  • 原文地址:https://www.cnblogs.com/liuyunche/p/13740003.html
Copyright © 2011-2022 走看看