사용자가 입력 한 정수를 읽는 프로그램을 함께 가져 오려고합니다. 나는 자바에서 이것을하는 가장 일반적인 방법 인 스캐너 클래스에 대해 읽었습니다. 그러나 like this one 사이트에 주어진 the examples 붙여 넣기를 복사하면 어떻게 수정해야하는지 알지 못하는 오류가 발생합니다. 게시 된 모든 내용이 문제가 없어야하는 완성 된 코드로되어 있기 때문에 어느 쪽이 실망 스럽습니까?스캐너 클래스가 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 {
그것은 나에게이 오류 제공 : 다음 줄 public static void main(String[] arguments){
에
Illegal modifier for the local class ScannerDemo; only abstract or final is permitted
를 내가이 오류를 얻을 : 나는 스캐너의 다양한 형태로 이것을 시도
The method main can not be declared static; static methods can only be declared in a static or top level type.
을 그 언제든지 갈 준비가되어 있고 때마다 오류가 발생합니다. 내가 도대체 뭘 잘못하고있는 겁니까? 어떻게 해결할 수 있습니까?
내가 처리 3. @Hovercraft 방금 ScannerDemo.java라는 파일에이 코드가 필요 언급 한 것처럼 내가 믿는
ScannerDemo가 로컬 클래스가 아니어야하며 파일의 유일한 클래스 여야하며 파일 이름은 ScannerDemo.java 여야합니다. –
핵심 정보이므로 가공 정보를 처리해야합니다. 처리는 ** Java가 아니므로 질문은 실제로 Java 문제가 아닙니다. –
나의 나쁜, 이것은 나의 첫번째 포스트 여기에있다. 나는 Processing이 java IDE 였다고 생각했다. –