




Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





1
(^1) {{736 Horstmann,Cay S. 2008 /s55}}
Section A. After each code fragment, indicate what output it produces when executed.
String s1 = new String( "Baylor" ); String s2 = new String( "Go Bears!"); String s3 = "Go Bears!"; String s4 = "Go Bears!"; String s5 = "Bears"; String s6 = "bears";
System. out .println("s1: " + s1 ); System. out .println("s2: " + s2 ); System. out .println("s3: " + s3 ); System. out .println("s4: " + s4 ); System. out .println("s5: " + s5 ); System. out .println("s6: " + s6 ); System. out .println();
System. out .print("Based on 'compareTo' operator, "); System. out .println("s5.compareTo(s6): " + s5.compareTo(s6));
System. out .print("Based on 'compareTo' operator, "); System. out .println("s6.compareTo(s5): " + s6.compareTo(s5));
System. out .print("Based on 'compareToIgnoreCase' operator, "); System. out .println("s5.compareToIgnoreCase(s6): " + s5.compareToIgnoreCase(s6));
Section B. As with the previous section, indicate what output is produced for each code
String strings[] = { “started”, “starting”, “ended”, “ending” }; String str1 = "Mississippi"; String str2 = "miss";
for ( String aString : strings ) { if ( aString.startsWith( “st” ) ) { System. out .println(aString + “ starts with ‘st’”); } }
for ( String aString : strings ) { if ( aString.startsWith( “art”, 2 ) ) { System. out .println(aString + “ starts with ‘art’ at position 2”); } }
String letters = "abcdefghijklmabcdefghijklm";
System. out .println("Last 'c' is located at index"
System. out .println (""def" is located at index"
System. out .println ("Last "def" is located at index"
String letters = "abcdefghijklmabcdefghijklm";
System. out .println("Substr from index 20 to end: "