我试图让一个程序一起读取用户输入的整数。我一直在阅读有关扫描仪类,这似乎是在java中这样做的最常见的方式。但是,当我复制+粘贴the examples给出的网站like this one我得到某种错误,我不知道如何解决。这是令人沮丧的,因为所有发布的东西都应该是完整的代码,应该没有问题!无法让扫描仪类在Java中工作
的一些代码,应该工作的一个例子:
import java.util.Scanner;
public class ScannerDemo {
public static void main(String[] arguments){
Scanner input = new Scanner(System.in);
String username;
double age;
String gender;
String marital_status;
int telephone_number;
// Allows a person to enter his/her name
Scanner one = new Scanner(System.in);
System.out.println("Enter Name:");
username = one.next();
System.out.println("Name accepted " + username);
// Allows a person to enter his/her age
Scanner two = new Scanner(System.in);
System.out.println("Enter Age:");
age = two.nextDouble();
System.out.println("Age accepted " + age);
// Allows a person to enter his/her gender
Scanner three = new Scanner(System.in);
System.out.println("Enter Gender:");
gender = three.next();
System.out.println("Gender accepted " + gender);
// Allows a person to enter his/her marital status
Scanner four = new Scanner(System.in);
System.out.println("Enter Marital status:");
marital_status = four.next();
System.out.println("Marital status accepted " + marital_status);
// Allows a person to enter his/her telephone number
Scanner five = new Scanner(System.in);
System.out.println("Enter Telephone number:");
telephone_number = five.nextInt();
System.out.println("Telephone number accepted " + telephone_number);
}
}
相反的程序运行,它给了我两个错误。
在行public class ScannerDemo {
它给了我这个错误:
Illegal modifier for the local class ScannerDemo; only abstract or final is permitted
在下一行public static void main(String[] arguments){
我得到这个错误:
The method main can not be declared static; static methods can only be declared in a static or top level type.
我曾与许多不同形式的扫描仪的尝试这一点,应该都准备好了,每次都会出错。我究竟做错了什么?我该如何解决它?
我使用的加工3.
ScannerDemo不应该是一个本地类,应该是文件中唯一的类,并且该文件应该被命名ScannerDemo.java。 –
您应该从开始就包含处理信息,因为它是关键信息。处理是**不是** Java,所以这个问题并不是真正的Java问题。 –
我的不好,这是我在这里的第一篇文章。我的印象是Processing是一个java IDE。 –