我想學習java與本網站:http://www.homeandlearn.co.uk/java/user_input.html 但是當我通過終端運行在Ubuntu的代碼中,我得到這些錯誤:爪哇 - 錯誤:<identifier>預計
[email protected]:~/Java_Applications$ javac StringVariables2.java
StringVariables2.java:3: error: '{' expected
public static class main(String[] args) {
^
StringVariables2.java:8: error: <identifier> expected
System.out.println("Please enter your first name")
^
StringVariables2.java:8: error: illegal start of type
System.out.println("Please enter your first name")
^
StringVariables2.java:8: error: ';' expected
System.out.println("Please enter your first name")
^
StringVariables2.java:12: error: <identifier> expected
System.out.println("Please enter your family name")
^
StringVariables2.java:12: error: illegal start of type
System.out.println("Please enter your family name")
^
StringVariables2.java:12: error: ';' expected
System.out.println("Please enter your family name")
^
StringVariables2.java:16: error: <identifier> expected
full_name = first_name +" "+ family_name;
^
StringVariables2.java:18: error: <identifier> expected
System.out.println("You are" + full_name);
^
StringVariables2.java:18: error: illegal start of type
System.out.println("You are" + full_name);
^
StringVariables2.java:18: error: ')' expected
System.out.println("You are" + full_name);
^
StringVariables2.java:18: error: ';' expected
System.out.println("You are" + full_name);
^
StringVariables2.java:18: error: illegal start of type
System.out.println("You are" + full_name);
^
StringVariables2.java:18: error: <identifier> expected
System.out.println("You are" + full_name);
^
StringVariables2.java:18: error: ';' expected
System.out.println("You are" + full_name);
^
StringVariables2.java:20: error: reached end of file while parsing
}
^
16 errors
[email protected]:~/Java_Applications$
下面是代碼:
import java.util.Scanner;
public class StringVariables2 {
public static class main(String[] args) {
Scanner user_input = new Scanner(System.in);
String first_name;
System.out.println("Please enter your first name")
first_name = user_input.next();
String first_name;
System.out.println("Please enter your family name")
first_name = user_input.next()
String full_name;
full_name = first_name +" "+ family_name;
System.out.println("You are" + full_name);
}
}
我使用Ubuntu 13.10 Saucy Salamander。
現在我得到這樣的:
[email protected]:~/Java_Applications$ javac StringVariables2.java
StringVariables2.java:13: error: variable first_name is already defined in method main(String[])
String first_name;
^
StringVariables2.java:18: error: cannot find symbol
full_name = first_name + " " + family_name;
^
symbol: variable family_name
location: class StringVariables2
2 errors
使用完整的IDE。不要在文本編輯器中編寫代碼。 –
您缺少一行一行的分號。 – Sajmon
Ubuntu與這個問題完全無關。 –