我在下面的这段代码中遇到了很多错误。
首先,“out”和“println”之间的每个句点都画一条红色下划线。错误内容为,'''- 标记上的语法错误,错误的构造'''
接下来,第 11 行的“println”有一个错误,读取“'- 标记“println”上的语法错误,= 在此标记之后预期”
此外,第 7,9 和 12 行中的 ("....") 短语表示,""""标记上的语法错误 ""(引号中的任何单词)"",删除此 token “””。
最后,第 13 行的分号有一个错误“”” - 标记“;”上的语法错误,{ 在此标记之后需要“””
提前感谢您的帮助! :)
import java.util.Scanner;
public class Tennis_Pro
{
public static void main(String[]args){
}
Scanner in=new Scanner(System.in);
System.out.println("Welcome to Tennis Pro. Please enter the name of player one:");
String playerone=in.nextLine();
System.out.println("And player two?");
String playertwo=in.nextLine();
System.out.println("The players today are "+playerone+" and "+playertwo+". is this correct?");
System.out.println("type y or n");
String yorn=in.nextLine();
if (yorn.equals ("y"))
{
//The game will go here
}
else if (yorn.equals ("m"))
{
}
}
}
最佳答案
所有代码都应该位于 main
方法内部。但该方法从第 4 行开始,并已在第 5 行结束。您应该将结束的 }
移动到第 21 行附近的某个位置。
顺便说一句,Scanner in = new Scanner(System.in);
行不会从编译器中产生错误消息,因为它在 in 中声明了一个字段类。其他行既不是变量声明,也不是方法体(也不是其中允许的其他元素),因此禁止直接在类中使用。
关于java - 在实验程序中出现一些与 System.out.println 相关的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7814661/