(From Lesson 17 of Blue Pelican Java)
Use the following code for problems 1 – 15. In each problem state what’s printed.
String s = “Lucky hockey puck”;
String m = “uck”;
int j = 6, z = 99;
1. int k = s.indexOf(m);
System.out.println(k);
2. int k = s.indexO”, j);
System.out.println(k);
3. int k = s.indexOf(‘c’);
System.out.println(k);
4. String str = s.replace(‘o’, ‘p’);
System.out.println(str);
5. int k = s.lastIndexOf(m, j + 3);
System.out.println(k);
6. char p = s.charAt(7);
System.out.println(p);
7. int k = s.indexOf(z);
System.out.println(k);
8. int k = s.lastIndexOf(m);
System.out.println(k);
9. int k = s.indexOf(‘y’, j);
System.out.println(k);
10. char p = s.charAt(z - 90);
System.out.println(p);
11. int k = s.indexOf(m,15);
System.out.println(k);
12. int k = s.indexOf(z + 2, 4);
System.out.println(k);
13. int k = s.lastIndexOf(‘h’);
System.out.println(k);
14. int k = s.lastIndexOf(121);
System.out.println(k);
15. String str = s.replace(‘y’, ‘A’);
System.out.println(str);
1 answer