My Report

Java String Handling Test – 3


Correct Answer: 2 points | Wrong: -1 point
Grades: A* (100% score) | A (80%-99%) | B (60%-80%) | C (40%-60%) | D (0%-40%)
advertisement

1. What will be the output of the following Java program?

   
    class output 
    {
        public static void main(String args[])
        { 
           String c = "  Hello World  ";
           String s = c.trim();
           System.out.println("\""+s+"\"");
        }
    }

2. What will be the output of the following Java program?

 
    class output 
    {
        public static void main(String args[])
        { 
           String s1 = "one";
           String s2 = s1 + " two";
           System.out.println(s2);
        }
    }

3. What will be the output of the following Java program?

 
    class output 
    {
        public static void main(String args[])
        {
           String s1 = "Hello World";
           String s2 = s1.substring(0 , 4);
           System.out.println(s2);
        }
   }

4. Which of these method of class String is used to remove leading and trailing whitespaces?

5. What will s2 contain after following lines of Java code?

 String s1 = "one";
String s2 = s1.concat("two")

6. What is the value returned by function compareTo() if the invoking string is greater than the string compared?

7. What will be the output of the following Java program?

 
    class output 
    {
        public static void main(String args[])
        { 
           String s1 = "Hello";
           String s2 = s1.replace('l','w');
           System.out.println(s2);
        }
    }

8. Which of this method of class String is used to extract a substring from a String object?

9. What will be the output of the following Java program?

    class output 
    {
        public static void main(String args[])
        {             String s = "Hello World";
             int i = s.indexOf('o');
             int j = s.lastIndexOf('l');
             System.out.print(i + " " + j);
 
        }
   }

10. Which of the following statement is correct?


 

Start practicing “1000 MCQs on Java”, and once you are ready, you can take tests on all topics by attempting our “Java Test Series”.

Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.