【发布时间】:2020-11-21 18:06:00
【问题描述】:
我要创建一个程序,用户必须在其中猜一个从 1 到 10 的数字,老师要求我们创建 6 种方法:一种是生成随机数,另一种是检查用户给出的答案和随机数相同,等等)我正在使用输入和随机数必须相同的方法,但我不确定我是否正确:
public class Guessgame {
static int a;
static int a1;
static int a2;
static int b;
public static void main(String[] args) {
Scanner input = new Scanner (System.in); // User input
b = generator(); //declara el numero aleatorio generado en "generator()"
System.out.println("Welcome to a game, you have to guess a number between 1 to 10");
System.out.println("You have three tries");
System.out.println(b);
System.out.println("What is your first guess?");
a = input.nextInt(); //declara el numero que declaro el usuario
evaluator();
}
这是评估器方法:
public static void evaluator(){
if ( a == b ){
System.out.println("Good");
}
else{
System.out.println("Bad");
}
}
我只需要更改 evaluator();给评估者(a, b);
【问题讨论】:
-
我强烈建议你和你的老师谈谈,让她/他向你解释。她/他知道他/她想教你什么以及如何教你。
-
这是一个证据:/我们不应该问他
标签: java class variables methods