我想学习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与这个问题完全无关。 –