Answered step by step
Verified Expert Solution
Question
1 Approved Answer
public class StringCompare { public static void main(String[] args) { int i; String s1 = new String(Test); String s2 = new String(Test); String [] a
public class StringCompare {
public static void main(String[] args) { int i;
String s1 = new String("Test"); String s2 = new String("Test"); String [] a = {s1, "test", "TEST", "TeSt"}; if (s1 == s2) System.out.println("Same"); for (i = 1; i < 3; i ++)
if (s2.equals(a[i-1])) s2 = s2 + " same as " + a[i-1];
System.out.println(s2); }
}
Can someone explain why this code prints what it prints? Please, explain how each line works. Thank you!
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started