标签:release java源码 while public 学习 imp ext eclips static
os :windows7 x64
jdk:jdk-8u131-windows-x64
ide:Eclipse Oxygen Release (4.7.0)
code:
package jizuiku.t00;
import java.util.Scanner;
public class Demo0 {
public static void main(String[] args) {
int max = 100;
int min = 0;
// goal的返回是[0,100],公式好强
int goal = (int) ((Math.random() * (max + 1 - min)) + min);
int count = 6;// 总共有六次机会
int userInput;// 用户的猜测
Scanner sc = new Scanner(System.in);
System.out.println("已经生成了[0,100]之间的一个数字,来玩猜数字的游戏吧!");
// 因为用户至少会输入一次数据,所以采用do-while结构
do {
// 程序提示上的优化
if (count == 6) {
System.out.println("你有" + count + "次机会进行输入");
} else {
System.out.println("还有" + count + "次机会");
}
// 接收用户的输入
userInput = sc.nextInt();
// 对用户的输入进行判断
if (userInput == goal) {
System.out.println("输入正确");
break;
} else {
System.out.println("输入错误,你的猜的" + (userInput > goal ? "大了" : "小了"));
}
} while ((--count) != 0);// 先进行count--,然后在不等于0的话进行开始下一轮
sc.close();
System.out.println("程序结束");
}
}
result:
Java优秀,值得学习。
学习资源:API手册+Java源码。
标签:release java源码 while public 学习 imp ext eclips static
原文地址:http://www.cnblogs.com/jizuiku/p/7469074.html