对循环,条件判断,键盘输入,随机数的练习
import java.util.Random;
import java.util.Scanner;
public class Test03 {
public static void main(String[] args) {
Random random = new Random();
//起始有三次机会
int count = 3;
//猜测范围
int guess = random.nextInt(1, 100);
//猜测边界
int original = 1;
int bound = 100;
//System.out.println(guess);
while (count >=0) {
//如果有猜测机会
if (count >0) {
count--;
System.out.println("请从"+ original+"到"+bound+"猜");
//猜测方法
int k = GuessNumber(guess,original,bound);
//更改提示边界
if(k == -1){
System.out.println("输入不合法,机会-1");
}else{
if(guess > k){original = k;}
if(guess bound){
return -1;
}
//判断猜测结果
else{
if (guess > inputN) {
System.out.print("猜小了");
} else if (guess < inputN) {
System.out.print("猜大了");
} else {
System.out.println("猜中了");
}
//返回输入的猜测值
return inputN;
}
}
//充值系统
public static int Charge() {
System.out.println("是否充值以增加次数?");
System.out.println("输入1充值,输入0退出程序");
Scanner scanner = new Scanner(System.in);
if (scanner.nextInt() == 1) {
System.out.println("您需要增加的次数");
return scanner.nextInt();
}
return -1;
}
}



