Java猜数字游戏代码

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

public class Caishuzi {
    public static void main(String[] args) {
        Random r=new Random();
        int number=r.nextInt(100)+1;
        while (true) {
            Scanner sc = new Scanner(System.in);
            System.out.println("请输入数字:");
            int guessNumber = sc.nextInt();
            if (guessNumber > number) {
                System.out.println("你猜的数字" + guessNumber + "大了");
            } else if (guessNumber < number) {
                System.out.println("你猜的数字" + guessNumber + "小了");
            } else {
                System.out.println("恭喜你猜对了");
                break;
            }
        }
    }
}

你可能感兴趣的:(java,游戏,python)