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); } }
3 Respuestas
+ 1
Thats i know Ipang what is the output of this code and why?
+ 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.
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))