复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25import java.util.Random; import java.util.Scanner; public class GuessGame { public static void main(String[] args) { Scanner scan = new Scanner(System.in); Random rand = new Random(); int result,n; result=rand.nextInt(10)+1; System.out.println("请猜一个[1,10]的数字"); while(true) { n = scan.nextInt(); if(n == result) { System.out.println("猜对了"); break; }else if(n > result) { System.out.println("猜大了"); }else { System.out.println("猜小了"); } } scan.close(); } }
最后
以上就是舒服树叶最近收集整理的关于猜数字游戏(Java)的全部内容,更多相关猜数字游戏(Java)内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复