黑马程序员技术交流社区
标题:
这个程序很好玩
[打印本页]
作者:
✦.灰机不会飞
时间:
2015-10-10 23:31
标题:
这个程序很好玩
/*
* 需求:猜数字小游戏(数据在1-100之间) 对于次数进行计数并且对次数进行评价
*/
import java.util.Scanner;
class Test_Math {
public static void main(String[] args) {
int count = 0;
Scanner sc = new Scanner(System.in);
System.out.println("请输入一个1-100的整数");
int x = (int)(Math.random() * 100) + 1;
while (true) {
int y =sc. nextInt();
count++;
if (y > x ) {
System.out.println("大了");
}
else if (y < x ) {
System.out.println("小了");
}
else{
System.out.println("中了");
if (count < 5) {
System.out.println("牛逼");
}
else if (count >= 5 && count <= 8) {
System.out.println("就那样");
}else{
System.out.println("菜鸟");
}
break;
}
}
System.out.println(count);
}
}
作者:
fwqk123
时间:
2015-10-11 18:45
有点意思 算是最容易做的游戏了?
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2