[java]代码库
package com.jrtc168.www;
import java.util.Scanner;
public class Guss {
Scanner scanner;
public Guss() {
scanner = new Scanner(System.in);
}
/**
* 猜数字
*
* @param num
*/
long radomNum = -9999999;
public boolean guss(long num) {
if (num <= 1000 && num >= 1) {
if (num > radomNum) {
System.out.println("太大了,再小点");
return false;
}
if (num < radomNum) {
System.out.println("太小了,再大点");
return false;
}
System.out.println("恭喜你猜对了" + radomNum);
return true;
}else{
System.out.println("请输入1-1000之间的数!");
return false;
}
}
boolean isStart = true;
boolean isCurrebt = false;
public void playGame() {
while (isStart) {
radomNum = (long) (Math.random() * 1000 + 1);
System.out.println("猜数字游戏开始");
System.out.println("请输入一个1-1000数:");
while (!isCurrebt) {
long userNum = scanner.nextLong();
isCurrebt = guss(userNum);
}
isCurrebt=false;
System.out.println("是否继续游戏? Y/N");
String isOrNo = scanner.next();
if (isOrNo.equalsIgnoreCase("Y")) {
isStart = true;
continue;
} else if (isOrNo.equalsIgnoreCase("N")) {
isStart = false;
System.out.println("游戏结束");
continue;
} else {
isStart = false;
System.out.println("游戏结束");
continue;
}
}
}
}
package com.jrtc168.www;
public class Main {
public static void main(String[] args) {
Guss guss=new Guss();
guss.playGame();
}
}
by: 发表于:2017-08-04 14:55:21 顶(0) | 踩(0) 回复
??
回复评论