Java Compliator-error(OSX)

时间:2014-08-29 10:51:26

标签: java macos compilation

我的java编译器中有一个非常奇怪的错误,我找不到解决方案。我正在运行OSX并安装了最新的Java版本,我尝试通过脚本编辑器(Sublime Test)和终端进行编译,两者都会导致同样的错误。

有趣的是,我可以在学校计算机(Linux)上编译此脚本而没有任何错误。

    import java.util.Scanner;

public class Billettpris{

    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);
        System.out.print("Oppgi din alder: ");

        int age = Integer.parseInt(sc.nextLine());

        if(age < 12 || age > 67){
            System.out.println("Du reiser for halv pris, 25 kr.");
        }else{
            System.out.println("Du reiser for full pris, 50 kr.");
        }

    }
}

然后我在编译时遇到了这个错误:

 /Users/Daniel/Dropbox/Skole/INF1000/Obliger/Oblig 1/Billettpris.java:12: illegal character: \172
        if(age < 12 || age > 67){
                      ^
/Users/Daniel/Dropbox/Skole/INF1000/Obliger/Oblig 1/Billettpris.java:12: illegal character: \8224
        if(age < 12 || age > 67){
                       ^
/Users/Daniel/Dropbox/Skole/INF1000/Obliger/Oblig 1/Billettpris.java:12: ';' expected
        if(age < 12 || age > 67){
                        ^
/Users/Daniel/Dropbox/Skole/INF1000/Obliger/Oblig 1/Billettpris.java:12: illegal start of expression
        if(age < 12 || age > 67){
                            ^
/Users/Daniel/Dropbox/Skole/INF1000/Obliger/Oblig 1/Billettpris.java:12: ';' expected
        if(age < 12 || age > 67){
                             ^
/Users/Daniel/Dropbox/Skole/INF1000/Obliger/Oblig 1/Billettpris.java:12: illegal start of expression
        if(age < 12 || age > 67){
                                ^
/Users/Daniel/Dropbox/Skole/INF1000/Obliger/Oblig 1/Billettpris.java:12: ';' expected
        if(age < 12 || age > 67){
                                 ^
/Users/Daniel/Dropbox/Skole/INF1000/Obliger/Oblig 1/Billettpris.java:14: illegal start of type
        }else{
         ^
/Users/Daniel/Dropbox/Skole/INF1000/Obliger/Oblig 1/Billettpris.java:14: ';' expected
        }else{
             ^
/Users/Daniel/Dropbox/Skole/INF1000/Obliger/Oblig 1/Billettpris.java:15: <identifier> expected
            System.out.println("Du reiser for full pris, 50 kr.");
                              ^
/Users/Daniel/Dropbox/Skole/INF1000/Obliger/Oblig 1/Billettpris.java:15: illegal start of type
            System.out.println("Du reiser for full pris, 50 kr.");
                               ^
/Users/Daniel/Dropbox/Skole/INF1000/Obliger/Oblig 1/Billettpris.java:18: class, interface, or enum expected
    }
    ^
12 errors
[Finished in 1.8s with exit code 1]

1 个答案:

答案 0 :(得分:1)

似乎您粘贴了具有不同字符编码的外部源代码。删除这一行:

  

if(age&lt; 12 || age&gt; 67){

然后逐个字符地键入它,这次不粘贴任何东西。这在过去对我有用。如果您不再为此行收到错误,请继续执行其他行并删除所有特殊字符{}()|和&#34;并自己输入。