Advanced Strings APCS JM Ch 8 String s






























![What is the output ? Public class My. Tester{ public static void main(String args[]){ What is the output ? Public class My. Tester{ public static void main(String args[]){](https://slidetodoc.com/presentation_image_h/9a9ee82f3019b187ac15c71a09cee239/image-31.jpg)
- Slides: 31
Advanced Strings APCS JM Ch 8
String s = “Lucky hockey puck”; String m = “uck’; int j = 6; z = 99; int k = s. index. Of(m); System. out. println(k); What is printed?
String s = “Lucky hockey puck”; String m = “uck’; int j = 6; z = 99; int k = s. index. Of(“uck”, j); System. out. println(k); What is printed?
String s = “Lucky hockey puck”; String m = “uck’; int j = 6; z = 99; int k = s. index. Of(‘c’); System. out. println(k); What is printed?
String s = “Lucky hockey puck”; String m = “uck’; int j = 6; z = 99; String str = s. replace(‘o’, ’p’); System. out. println(str); What is printed?
String s = “Lucky hockey puck”; String m = “uck’; int j = 6; z = 99; int k = s. last. Index. Of(m, j + 3); System. out. println(k); What is printed?
String s = “Lucky hockey puck”; String m = “uck’; int j = 6; z = 99; char p = s. char. At(7); System. out. println(p); What is printed?
String s = “Lucky hockey puck”; String m = “uck’; int j = 6; z = 99; int k = s. last. Index. Of(m); System. out. println(k); What is printed?
String s = “Lucky hockey puck”; String m = “uck’; int j = 6; z = 99; int k = s. index. Of(z); System. out. println(k); //hint: z is 99 (the ASCII code for ‘c’) What is printed?
String s = “Lucky hockey puck”; String m = “uck’; int j = 6; z = 99; int k = s. index. Of(‘y’, j); System. out. println(k); What is printed?
String s = “Lucky hockey puck”; String m = “uck’; int j = 6; z = 99; char p = s. char. At(z - 90); System. out. println(p); What is printed?
String s = “Lucky hockey puck”; String m = “uck’; int j = 6; z = 99; int k = s. index. Of(m, 15); System. out. println(k); What is printed?
String s = “Lucky hockey puck”; String m = “uck’; int j = 6; z = 99; int k = s. index. Of(z + 2, 4); System. out. println(k); //hint: z + 2 = 101 ASCII code for ‘e’ What is printed?
String s = “Lucky hockey puck”; String m = “uck’; int j = 6; z = 99; int k = s. last. Index. Of(121); System. out. println(k); //hint: 121 ASCII code for ‘y’ What is printed?
String s = “Lucky hockey puck”; String m = “uck’; int j = 6; z = 99; String str = s. replace(‘y’, ’A’); System. out. println(str); What is printed?
What’s printed? String xyz = “bathtub”; String ddd = “Bath. TUB”; String ccc = xyz; String wc = “Whooping crane”; String s = “ tt. Gu daay, mates n”; int j = xyz. compare. To(wc); boolean bb; if(j > 0) { bb = true; } else { bb = false; } System. out. println(bb);
What’s printed? String xyz = “bathtub”; String ddd = “Bath. TUB”; String ccc = xyz; String wc = “Whooping crane”; String s = “ tt. Gu daay, mates n”; String v = ddd. to. Lower. Case(); int fg = ccc. compare. To(v); System. out. println(fg + 1);
What’s printed? String xyz = “bathtub”; String ddd = “Bath. TUB”; System. out. println(ddd. compare. To(ccc)); String ccc = xyz; String wc = “Whooping crane”; String s = “ tt. Gu daay, mates n”;
What’s printed? String xyz = “bathtub”; String ddd = “Bath. TUB”; System. out. println(xyz. compare. To(ccc)); String ccc = xyz; String wc = “Whooping crane”; String s = “ tt. Gu daay, mates n”;
What’s printed? String xyz = “bathtub”; String ddd = “Bath. TUB”; System. out. println(“>>>” + s. trim() + “<<<“); String ccc = xyz; String wc = “Whooping crane”; String s = “ tt. Gu daay, mates n”;
What is returned by do. Stuff(“I would if I could”)? public class My. Tester { public static int do. Stuff(String my. String) { int cc = 0; int p = my. String. length()/2 for(k = 0; k < my. String. length()/2; k++, p++) if(my. String. char. At(k) == my. String. char. At(p)) c++; return cc; } } • 1 • 2 • 3 • 4 • None of these
What is returned by do. Stuff(“fee fi fo fum”)? public class My. Tester { public static int do. Stuff(String my. String) { int cc = 0; int p = my. String. length()/2 for(k = 0; k < my. String. length()/2; k++, p++) if(my. String. char. At(k) == my. String. char. At(p)) c++; return cc; } } • 1 • 2 • 3 • 4 • None of these
What is the output with the method call convert(“Abe Lincoln”) public class My. Tester { public static void(String my. String) { string tot = “”; for(int j = 0; j<my. String. length(); j++) { char c = Character. to. Upper. Case(my. String. char. At(j)); tot = tot + ch; } System. out. println(tot); } } • • • ABELINCOLN ABE LINCOLN abe lincoln None of these
What is the output with the method call convert(“BR 549”) public class My. Tester { public static void(String my. String) { string tot = “”; for(int j = 0; j<my. String. length(); j++) { char c = Character. to. Upper. Case(my. String. char. At(j)); tot = tot + ch; } System. out. println(tot); } } • • • Throws an exception Nothing BR 549 Br 549 None of these
What is the output with the method call bail. On. M(“mumify”) public class My. Tester { public static int bail. On. M(String. my. String) { int index = 0; do { index++; }while(my. String. char. At(indx)!=‘m’); return indx; } } • • • 0 1 2 6 None of these
What is the output with the method call print. Stuff(“A 1 USDA prime. ”)? public class My. Tester { public static void print. Stuff(String the. String) { for(int j = 0; j<the. String. length(); j++) { char chr = the. String. char. At(j); if(Character. is. Letter(chr)) System. out. println(chr); } } } • AUSDAprime • A USDA prime. • 1 • A USDA PRIME. • None of these
What is the output with the method call elim(“ABC 1234 DEF”) public class My. Tester { public static double elim(String the. String) { int sum = 0; for(int j=0; j<the. String. length(); j++) { if(the. String. char. At(j)>’ 1’ && the. String. char. At(j)<‘ 8’) sum = sum + the. String. char. At(j) * 2; } return sum; } } • • • Throws an exception 0 18. 0 306. 0 None of these
What is the output by System. out. println(“Alf Abrams”. index. Of(‘A’)); • 0 • 1 • 4 • 65 • None of these
What is the output by System. out. println(“Alf Abrams”. last. Index. Of(‘A’)); • 0 • 1 • 4 • 65 • None of these
What is the output with a method call, do. Stuff(“ 3872345619”)? public static void do. Stuff(String a. String) { int p=1; int j = a. String. index. Of(“ 23”) + p; String s; System. out. print(j); if(j>=0) s = a. String. substring(j, J+4); else s = “No can do”; System. out. println(s + “>>>” + j%3); } • • • 42345>>>0 43456>>>1 42345>>>1 64345619>>>1 None of these
What is the output ? Public class My. Tester{ public static void main(String args[]){ System. out. println(“Nertz to you”. char. At(4)); } } • blank • t • e • Won’t compile • None of these