猜数游戏代码
佛系小姐姐 人气:5import java.util.Scanner;
public class Namble1 {
public static void main(String[] args) {
int count = 1;
System.out.println("游戏>登录");
System.out.println("请输入用户名:");
Scanner input = new Scanner(System.in);
String name = "zhangsan";
name = input.next();
System.out.println("请输入密码:");
String mima = "123456";
mima = input.next();
if ("zhangsan".equals(name)) {
if ("123456".equals(mima)) {
System.out.println("********************************************");
System.out.println("游戏>登陆成功>猜数游戏");
System.out.println("游戏开始——已随机生成一位17-97的数字");
System.out.println("********************************************\n");
int num;
int randNum = (int) (Math.random() * (97 - 17+ 1) + 17);
do {
System.out.println("请第"+count+"输入您猜的数字:");
num = input.nextInt();
if (num > randNum) {
System.out.println("太大了...");
}else if (num<randNum){
System.out.println("太小了...");
}
count++;
} while (num != randNum && count<20);
if (count == 1) {
System.out.println("你太有才了");
}
if (2 <= count && count >= 6){
System.out.println("这么快就猜出来了,很聪明嘛");
}
if (20>count&&count >= 7) {
System.out.println("小同志,还需努力呀");
}
if(count>20){
System.out.println("次数用尽");
}
}
} else {
System.out.println("登录游戏失败,退出游戏");
}
System.out.println("——游戏结束——");
}
}
加载全部内容