Consider the following code segment.
String a = ""; a += "0"; if (a == "0") { System.out.println("a is 0!"); } else if (a == "1") { System.out.println("a is 1!"); } else if (a == "a") { System.out.println("a is a!"); } else { System.out.println("a is something else!"); }
Which of the following statements about the code segment is true?
It produced "a is 0!" as output
It produced "a is 1!" as output
It produced "a is a!" as output
It produced "a is something else!" as output
It results in an error because the == operation can not be used with Strings
Answers
Answered by
5
It will results in an error because == cannot be used with strings.
With strings we use .equals().
Thaink
With strings we use .equals().
Thaink
Similar questions