我正在尝试做一个简单的输入程序,我在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();
}
答案 0 :(得分:4)
试试这个:
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中,您必须将代码放在方法中,而不是在类级别。特别是,您可以将其放在main()
方法中,这是执行所有程序的入口点。
答案 1 :(得分:0)
你错过了什么.....但你可以尝试这个"用户输入"代码
import java.util.Scanner;
public class test {
public static void main(String args[])
{
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();
}
}
答案 2 :(得分:0)
import java.util.Scanner;
class Multi {
public static void doSomething() {
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 MultiplicationTable {
public static void main(String[] args) {
Multi.doSomething();
}
}
答案 3 :(得分:0)
public class Animal {
public String name;
public static int nosLegs;
public Animal(){
}
public Animal(String name, int nosLegs) {
super();
this.name = name;
this.nosLegs = nosLegs;
}
//getter and setter
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getNosLegs() {
return nosLegs;
}
public void setNosLegs(int nosLegs) {
this.nosLegs = nosLegs;
}
public class B{
public int b;
System.out.println("hello");
}
}
change in Main method...