-5

I accidentally wrote something like this on NetBeans:

System.out.println(("Apples") System.out.println("Oranges"));

It initially showed me no error, compiled and the output was:

Apples
Oranges

After running it started showing me an error but it still compiled and gave the same output.

Also, is System.out.println((grade/=3) + "%") a valid statement?

EDIT: As people are saying that it is not compiling, here is a screenshot: http://s1.postimg.org/m1ezmm3vz/Untitled.png It is compiling for me :/

  • 2
    `System.out.println(("Apples") System.out.println("Oranges"));` is showing compile time error http://ideone.com/lJPxYl and `System.out.println((grade/=3) + "%")` is like `System.out.println((grade =grade/3) + "%")` and its valid http://ideone.com/Mk2K71 – singhakash Sep 30 '15 at 05:43
  • 1
    doesn't work compile error for me – Madhawa Priyashantha Sep 30 '15 at 05:44
  • 1
    Considering grade as a int or float variable, `System.out.println((grade/=3) + "%")` is a valid statement. – Naman Gala Sep 30 '15 at 05:44
  • 3
    Are you sure it compiled? If compilation failed you might be running an older version of the code (the last one that did compile). - Don't know if netbeans works like that or not... – John3136 Sep 30 '15 at 05:46
  • i dont know about netbeans but in eclipse its showing compile time error...!!! are you sure its working??? – Shailesh Yadav Sep 30 '15 at 05:55

2 Answers2

1

The second statement is valid:

System.out.println((grade/=3) + "%");

Here the (grade/=3) is calculated first and then % is appended.

But the

System.out.println(("Apples") System.out.println("Oranges")); 

is invalid statement. For this case compiler generates compilation errors like :

error: ')' expected
error: illegal start of expression
error: ';' expected
Madhawa Priyashantha
  • 9,633
  • 7
  • 33
  • 60
0

The first statement does not compile or execute in Eclipse or using Command Line options. Similar queries have been answered in this thread for Netbeans compiler

Which java compiler is used by NetBeans?

Community
  • 1
  • 1
Saurav
  • 118
  • 9