Answered step by step
Verified Expert Solution
Link Copied!

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Big Data In Just 7 Chapters

Authors: Prof Marcus Vinicius Pinto

1st Edition

B09NZ7ZX72, 979-8787954036

Students also viewed these Databases questions