我是java的新手,因为我昨天刚刚开始,我正在尝试制作一个随机数生成的小游戏,你必须尝试猜测这个数字。我现在遇到的问题是控制台没有任何问题。我不确定是什么导致这个,因为它可能是我正在使用的代码或解释器。这是你们检查的代码。让我知道我做错了什么,如果你能找到解决方案,谢谢。
import java.util.Scanner;
public class Random
{
int Ran = (int) Math.floor(Math.random() * 9);
Scanner input = new Scanner(System.in);
int Num = input.nextInt();
public static void main(String[] args){}
{System.out.println("Geuss a number and see if it is correct!");
}
{
if (Num == Ran)
{System.out.println("Correct! The number was " + Ran);
}
else{
System.out.println("You are wrong!");
}
}
public void If(boolean b) {}
}
答案 0 :(得分:0)
你有空{}
public static void main(String[] args){
System.out.println("Geuss a number and see if it is correct!");
}
也不要将IF写为函数。如果是本机编码中的本机表达式。 已经有if子句,所以尝试给出唯一的名称。
import java.util.Scanner;
public class Random
{
int Ran = (int) Math.floor(Math.random() * 9);
Scanner input = new Scanner(System.in);
int Num = input.nextInt();
public static void main(String[] args)
{
System.out.println("Geuss a number and see if it is correct!");
if (Num == Ran)
{System.out.println("Correct! The number was " + Ran);
}
else{
System.out.println("You are wrong!");
}
}
}
答案 1 :(得分:0)
试试这个。
import java.util.Scanner;
public class Random
{
int Ran = (int) Math.floor(Math.random() * 9);
Scanner input = new Scanner(System.in);
int Num = input.nextInt();
public static void main(String[] args){
System.out.println("Geuss a number and see if it is correct!");
if (Num == Ran)
{System.out.println("Correct! The number was " + Ran);
}
else{
System.out.println("You are wrong!");
}
}
public void If(boolean b) {}
}
}