My Report

Java String Handling Test – 2


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 code?

 
    class output 
    {
        public static void main(String args[])
        {
            char ch;
            ch = "hello".charAt(1);
            System.out.println(ch);
        }
   }

2. Which of these methods is an alternative to getChars() that stores the characters in an array of bytes?

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

    class output 
    {
        public static void main(String args[])
        {
            char c[]={'a', '1', 'b' ,' ' ,'A' , '0'};
            for (int i = 0; i < 5; ++i)
            {
                   if(Character.isDigit(c[i]))
                       System.out.println(c[i]+" is a digit");
                   if(Character.isWhitespace(c[i]))
                       System.out.println(c[i]+" is a Whitespace character");
                   if(Character.isUpperCase(c[i]))
                       System.out.println(c[i]+" is an Upper case Letter");
                   if(Character.isLowerCase(c[i]))
                       System.out.println(c[i]+" is a lower case Letter");
               i=i+3;
            }
        }
    }

4. What will be the output of the following Java code?

 
public class Boxer1 
{
    Integer i;
    int x;
   public Boxer1(int y) 
   {
        x = i+y;
        System.out.println(x);
   }
   public static void main(String[] args) 
   {
       new Boxer1 (new Integer(4));
   }
}

5. In the following Java code, what can directly access and change the value of the variable name?

   
 package test;
 class Target 
 {
  public String name = "hello";
 }

6. Which of these methods can be used to convert all characters in a String into a character array?

7. Which of these method of class String is used to extract more than one character at a time a String object?

8. What will be the output of the following Java code?

   
    class output 
    {
        public static void main(String args[])
        { 
           String c = "Hello i love java";
           int start = 2;
           int end = 9;
           char s[]=new char[end-start];
           c.getChars(start,end,s,0);
           System.out.println(s);
        }
    }

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

 
    class output 
    {
        public static void main(String args[])
        {
            String a = "hello i love java";
            System.out.println(a.indexOf('i')+" "+a.indexOf('o') +" "+a.lastIndexOf('i')+" "+a.lastIndexOf('o'));
        }
    }

 

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.