我是靠谱客的博主 重要大门,这篇文章主要介绍do-while猜数字,现在分享给大家,希望可以做个参考。

import java.util.*;
public class hhh {
    public static void main(String[] args) {
        Random ran = new Random();
        int num = ran.nextInt(51) + 50;
        int guess;
        int count = 0;
        Scanner input = new Scanner(System.in);
        System.out.println("请猜一个50-100的整数");
        do {
            guess=input.nextInt();
            if (guess > num)
                System.out.println("你猜大了,再猜小一点");
            else
                if (guess < num)
                System.out.println("你猜小了,再猜大一点");
            else {
                System.out.println("恭喜你猜对了");
                    break;
            }
            count++;
            System.out.println("你的剩余"+(5-count)+"次机会");
        }while (count < 5) ;
    }
}

最后

以上就是重要大门最近收集整理的关于do-while猜数字的全部内容,更多相关do-while猜数字内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(52)

评论列表共有 0 条评论

立即
投稿
返回
顶部