rod*_*eal 1 java eclipse java.util.scanner output
我正在尝试执行一个简单的输入程序,但在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
Run Code Online (Sandbox Code Playgroud)
我的代码如下。
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();
}
Run Code Online (Sandbox Code Playgroud)
尝试这个:
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();
}
}
Run Code Online (Sandbox Code Playgroud)
在 Java 中,您必须将代码放在方法中,而不是在类级别。特别是,你可以把它放在main()方法里面,它是所有程序执行的入口点。
| 归档时间: |
|
| 查看次数: |
4714 次 |
| 最近记录: |