0

I'm learning Java, and I wanted to make a very basic calculator. But looks like I got a problem right a way!

Here is the code:

import java.util.Scanner;

public class apples{
    public static void main(String args[]){
        int test = 6;
        if(test != 9){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}

So in Eclipse I tried to run this but the problem is it does not work and show this error:

Exception in thread "main" java.lang.Error: Unresolved compilation problem:

at apples.main(apples.java:4)

3 Answers3

3

Your second last bracket has some invisible character that you can see a red point(very thin) and if you delete the same your program is perfectly ok.

Incorrect Code having special character in it

import java.util.Scanner;

    public class AdvanceCollection {
     public static void main(String args[]){
                Scanner scan = new Scanner(System.in);
                double fnum, snum, answer;
                System.out.println("Enter first number: ");
                fnum = scan.nextDouble();
                System.out.println("Enter second number: ");
                snum = scan.nextDouble();
                answer = fnum + snum;
                System.out.println(answer);
     }
     }

Correct code with out that issue

import java.util.Scanner;

public class AdvanceCollection {
 public static void main(String args[]){
            Scanner scan = new Scanner(System.in);
            double fnum, snum, answer;
            System.out.println("Enter first number: ");
            fnum = scan.nextDouble();
            System.out.println("Enter second number: ");
            snum = scan.nextDouble();
            answer = fnum + snum;
            System.out.println(answer);
 }
 }
so_what
  • 176
  • 10
2

Change your character at the end to }.

Vy Do
  • 46,709
  • 59
  • 215
  • 313
  • The error is `java: illegal character: \65279`, `java: reached end of file while parsing.` – Vy Do Jan 16 '18 at 08:53
1

There is no compilation error, just noticed last } is having some invisible character with it. delete it and type again }. Hopefully it should work. It works for me.

spandey
  • 1,034
  • 1
  • 15
  • 30
  • I don't know whom make your answer negative but your answer was true... But I tried other code (which I added it to the question instead of the previous one) and it gets me the same error. So what is your suggestion about that ?! Thanks –  Jan 16 '18 at 08:59
  • It says `Syntax Error on token "Invalid character", delete this token` –  Jan 16 '18 at 09:01
  • But whenever I try to delete the **}** and add another , it happens again –  Jan 16 '18 at 09:01
  • https://stackoverflow.com/questions/9180981/how-to-support-utf-8-encoding-in-eclipse refer this link for utf 8 slandered. looks like your eclipse has some different setting. – spandey Jan 16 '18 at 09:04