一个猜数小游戏

柔光的暖阳◎ 2022-05-21 11:04 334阅读 0赞

在零到一百猜数字,提醒你偏大或偏小,直到猜出正确数字。。

  1. import java.util.*;
  2. public class SetMath {
  3. public static void main(String[] args) {
  4. // TODO Auto-generated method stub
  5. Scanner in =new Scanner(System.in);
  6. int number =(int) (Math.random()*100+1);
  7. int count=0;
  8. int a;
  9. do {
  10. a=in.nextInt();
  11. count+=1;
  12. if(a>number) {
  13. System.out.println("偏大");
  14. }
  15. else if(a<number) {
  16. System.out.println("偏小");
  17. }
  18. }
  19. while(a!=number);
  20. System.out.println("太棒了,你猜对了。你猜了:"+count+"次。");
  21. }
  22. }

发表评论

表情:
评论列表 (有 0 条评论,334人围观)

还没有评论,来说两句吧...

相关阅读

    相关 用java实现游戏

    规则: 随机生成一个0~99(包括0和99)的数字,从控制台输入猜测的数字,系统提示输出用户输入的数太大还是太小, 猜不对则继续,直到猜到为止,游戏过程中,记录猜对所需的次

    相关 游戏

    一个小小的程序,找点乐趣。。哈哈 目前我觉得能最快的找出数字的方法是二分法。。。 代码: \include <stdio.h> \include <stdlib.h>

    相关 游戏

    猜数小游戏: 1. 从键盘录入你猜的数; 2. 比较环节,如果猜大了,提示猜大了重新猜测;如果猜小了,提示猜小了重新猜测;如果相等,提醒猜中了。 3. 循环环节,