Java Strings: Article Quizzes |
Quiz 1: Introducing some important methods of Java Strings
What is written to the standard output as the result of executing the following code?
public class MyString { String str = "All that we are is the result of what we have thought. Buddha"; public static void main(String[] args){ MyString ms = new MyString(); char c = ms.str.charAt(5); boolean b = ms.str.contains("w"); boolean b2 = ms.str.contains("z"); int i = ms.str.indexOf("e"); System.out.print(c + "-" + b + "-" + b2 + "-" + i); } }
Quiz 2: What can you do with the replace and replaceAll methods?
The “str” statement is not correct.
It should be “Be the change that you wish to see in the world.”
Which one of the following claims is true?
public class MyString { public static void main(String[] args){ String str = "Be zhe change zhat you wish zo see in zhe world. Gandhi"; String str2 = str.replaceAll("z","t"); String str3 = str.replaceFirst("z","t"); String str4 = str.replace('z','t'); System.out.println("str2: " + str2); System.out.println("str3: " + str3); System.out.println("str4: " + str4); } }
Java Strings: Article Quizzes |
Too many coemmiplnts too little space, thanks!
Thank.I hope the material will help.
What I find so insnrettieg is you could never find this anywhere else.