import java.util.Random;
import java.util.Scanner;
public class Chenwei_GuessNumber{
static int m=8;
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner(System.in);
Random ran = new Random();
int number = ran.nextInt(100)+1; // 产生随机数
for (;;)
{
System.out.println("1.开始猜数");
System.out.println("2.游戏参数设置");
System.out.println("9.退出");
Scanner sc=new Scanner(System.in);
String choo =sc.next();
if (!choo.equals("1")&&!choo.equals("2")&&!choo.equals("9"))
{
System.out.println("属于非法输入");
}
else
{
if (choo.equals("1"))
{
int guess; // 用户猜的数字
int count = 0; // 猜测次数
System.out.println("有一个0到100之间的整数,你猜是什么?");
do {
guess = input.nextInt();
if (number < guess) {
System.out.println("大了,再猜");
count++; } else if (number > guess) { System.out.println("小了,再猜"); count++; } else { count++; break; } if (guess > count){ System.out.println("次数超过"); break; } else if(guess <= count) { {break;} } else if(choo.equals("2")){ System.out.println("请选择难度:"); System.out.println("1.简单"); System.out.println("2.一般"); System.out.println("3.困难"); Scanner ssc = new Scanner(System.in); int n = ssc.nextInt(); if (n==1) { m=8; } else if(n==2) { m=6; } else { m=4; } } else {break;} } } while (true);{ System.out.println("这个数字是" + number); String count; System.out.println("您猜的次数" + count); } } } }
// 根据猜测次数给出评价
if (count >= 1 && count <= 3) {
System.out.println("厉害啊,兄弟!");
} else if (count >= 4 && count <= 6) {
System.out.println("不错,再接再厉!");
} else {
System.out.println("菜的真实!");
}
input.close();
}
}
eclipse中
Syntax error, insert "while ( Expression ) ;" to complete DoStatement
Syntax error on token "}", { expected after this token
删除了break的分号
底下的count报错。
pss:
现在是这样的