Quizzes – Java Strings

The following Java exercise(s) are designed to help you understand the article to which it belongs. If the following quizzes are too hard, then I recommend to read the article first, which offers a theoretical explanation including examples and exercises.
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);

Select the correct answer.


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);

Select the correct answer.

Please, leave your questions, feedback and suggestions in the comments below! If you need more explanation by any of the answers, just let me know to update it for you!

Megisoft.com offers a practical method to learn and improve your Java skills. It avoids unnecessary long boring theoretical explanations, but it uses many exercises and quizzes. The author of Megisoft is Sar Maroof who has more than a decade of experience with web development mainly with Java, MySql, HTML and more..

Java Strings: Article  Quizzes

Suggested Articles:

Sar Maroof's New Book "Java Quizmaster For Beginners"
Author: Sar Maroof
Many years of experience with developing web applications mainly with Java.
Sun Certified JSP as well as EJB
CIW Certified Internet Webmaster
Applied Science in Physics HBO Amsterdam
Bachellor Science in Physics at Basra university.
Share on FacebookTweet about this on TwitterShare on RedditShare on LinkedIn


Add a Comment
  1. Too many coemmiplnts too little space, thanks!

  2. Thank.I hope the material will help.

    1. What I find so insnrettieg is you could never find this anywhere else.

Leave a Reply

megisoft © 2016