赞
踩
- import java.util.Random;
- import java.util.Scanner;
-
- //猜数小游戏
- public class while1 {
- public static void main(String[] args) {
- // 在1-100内生成一个随机整数
- Random random = new Random();
- int start = 1;
- int end =600;
- // 统计猜了多少次
- int num = random.nextInt(start,end+1);
-
- int index =0;
- while (true) {
- Scanner scanner = new Scanner(System.in);
- System.out.printf("请输入数字[%d-%d]:", start, end);
- // 输入临时变量:temp
- int temp = scanner.nextInt();
- ++index;
- if (temp > num) {
- System.out.printf("\033[32m%d你猜得太大了\033[0m%n", index);}
- else {
- if (temp < num) {
- System.out.printf("\033[32m%d你猜得太小了\033[0m%n", index);}
- else {
- System.out.printf("\033[32m%d恭喜你猜对了!,你的得分是%d分\033[0m%n", index, (110 - index * 10));
- System.out.println();
- System.out.println("游戏退出!");
- break;}
- }
- }
- }
- }
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。