GuessNumber.java
资源名称:game.rar [点击查看]
上传用户:shxinshu
上传日期:2021-05-17
资源大小:3k
文件大小:1k
源码类别:
游戏
开发平台:
Java
- package GuessNumber;
- import java.util.Scanner;
- public class GuessNumber {
- /**
- * @猜数字游戏,范围是1~100
- * @author 刘李娟
- * @version 1.0
- */
- public static void main(String[] args) {
- int num = (int) (Math.random() * 100); // 产生一个数字:(1,100)
- int guess = 0;
- int count = 1;
- System.out.println(num);
- do {
- Scanner sca = new Scanner(System.in);
- System.out.println("第" + count + "次输入的数字为:");
- guess = sca.nextInt();
- if (guess > num) {
- System.out.println("太大啦!");
- } else if (guess < num) {
- System.out.println("太小啦!");
- } else if (guess == num) {
- System.out.println("恭喜你,猜对了!天才啊!");
- }
- count++;
- } while (count <= 10);
- System.out.println("猜了十次了,你好笨哪!");
- }
- }