我正在尝试执行一个简单的输入程序,但出现错误System.out.println
命令,我不知道为什么它不接受该命令并且在我修复它之前无法继续工作。
错误说:
Multiple markers at this line
- Syntax error, insert ")" to complete MethodDeclaration
- Syntax error, insert "Identifier (" to complete
MethodHeaderName
- Syntax error on token ".", @ expected after this token
- Syntax error, insert "SimpleName" to complete QualifiedName
我的代码如下。
package classPack;
import java.util.Scanner;
public class Main {
Scanner s = new Scanner(System.in);
int numone = s.nextInt();
System.out.println("please input the number of numbers you want to analyze");
Scanner r = new Scanner(System.in);
int numtwo = s.nextInt();
}
尝试这个:
public class Main {
public static void main(String[] args) {
// you only need one instance of scanner
Scanner s = new Scanner(System.in);
int numone = s.nextInt();
System.out.println("please input the number of numbers you want to analyze");
int numtwo = s.nextInt();
// don't forget to close the scanner
s.close();
}
}
在Java中,您必须将代码放入其中methods,不是在班级层面。特别是,您可以将其放入main()
方法,它是所有程序执行的入口点。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)