0

Output of the code ?and how?

public class Program { public static void main(String[] args){ String s="a"; String v="x"; String t=s+v; String z="ax"; if (t==z){ System.out.println (1); } else System.out.println(0); } }

28th Nov 2019, 2:49 AM
Cheliyan
Cheliyan - avatar
3 Antworten
+ 1
Thats i know Ipang what is the output of this code and why?
28th Nov 2019, 3:18 AM
Cheliyan
Cheliyan - avatar
+ 1
The output must be 0 because the assignment of the string "t" occur at the run-time and it is not considered as constant from the string pool. Edit: make both your "s" and "v" variable as final and you will get "1" as answer. Since the final keyword makes them a constant.
28th Nov 2019, 3:57 AM
Avinesh
Avinesh - avatar
0
Please edit your question and add Java in question tags. Use `equals` method from string class if you want to compare string content. if(t.equals(z))
28th Nov 2019, 3:03 AM
Ipang