+ 2

output of this code?

public class TestProgram { public static void main(String[] args) { String tie = null; while ( tie = null ){ tie = "you are from mars"; System.out.print(tie); } }}

26th Mar 2018, 12:39 PM
Anil
Anil - avatar
2 Answers
+ 4
I think it will give compile time error because condition should be a Boolean expression in Java.
26th Mar 2018, 1:01 PM
Nikhil Sharma
Nikhil Sharma - avatar
+ 6
Yep as @Nikhil says , you are using the assignment operator ( = ) when you should be using == So it will give you the output you want if you do (tie == null )
26th Mar 2018, 1:12 PM
Tarantino
Tarantino - avatar