package youkuaiyun.com;
import java.util.Random;
import java.util.Scanner;
public class lianxi3YX {
public static void main(String[] args) {
Random r = new Random();
int i, c = 1;
i = r.nextInt(9);
System.out.println("请猜10以内的数字:");
while (true) {
Scanner number = new Scanner(System.in);
int f = number.nextInt();
if (c <= 3) {
c = c + 1;
if (f > 0 && f < 10) {
if (i > f) {
System.out.println("小了");
} else if (i < f) {
System.out.println("大了");
} else {
System.out.println("猜对了");
break;
}
} else {
System.out.println("超出范围了,笨蛋!");
}
} else {
System.out.println("3次都猜不出来...,笨的和肖志旭似得呢!");
break;
}
}
}
}
import java.util.Random;
import java.util.Scanner;
public class lianxi3YX {
public static void main(String[] args) {
Random r = new Random();
int i, c = 1;
i = r.nextInt(9);
System.out.println("请猜10以内的数字:");
while (true) {
Scanner number = new Scanner(System.in);
int f = number.nextInt();
if (c <= 3) {
c = c + 1;
if (f > 0 && f < 10) {
if (i > f) {
System.out.println("小了");
} else if (i < f) {
System.out.println("大了");
} else {
System.out.println("猜对了");
break;
}
} else {
System.out.println("超出范围了,笨蛋!");
}
} else {
System.out.println("3次都猜不出来...,笨的和肖志旭似得呢!");
break;
}
}
}
}
猜数字游戏实现
本文介绍了一个简单的Java猜数字游戏程序,使用Random生成10以内的随机数,玩家有三次机会猜测正确的数字。程序通过Scanner接收用户输入并给出提示。
4102

被折叠的 条评论
为什么被折叠?



