java - Random18

猜数字案例

package com.demo.test;

import java.util.Random;
import java.util.Scanner;

public class rr {
    public static void main(String[] args) {
        r();
    }
    public static void r() {
        Scanner sc = new Scanner(System.in);
        Random r = new Random();
        int num = r.nextInt(100);

        while (true){
            int num2 = sc.nextInt();
            if (num > num2){
                System.out.println("您猜小了");
            }else if (num < num2){
                System.out.println("您猜大了");
            }else {
                System.out.println("您猜对了");
                break;
            }
        }
    }
}

  

posted @ 2023-03-02 17:31  文采呱呱  阅读(13)  评论(0编辑  收藏  举报