Java猜数字游戏程序:

import java.util.Random;
import java.util.Scanner;
public class csz01 {
public void run(){
}

public static void main(String[] args) {
System.out.println("程序开始");
Random r = new Random();

int csz = r.nextInt(100) + 1;
while (true){
Scanner sc = new Scanner(System.in);
System.out.println("请输入一个数字");
int youxi = sc.nextInt();
if (youxi >csz) {
System.out.println("您猜的数字" + youxi + "大了");
} else if (youxi < csz){
System.out.println("您猜的数字" + youxi + "小了");
} else {
System.out.println("恭喜您猜对了");
break;
}
}
System.out.println("程序结束");
}

}

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