Searching & Modifying a String

1

What is the output of this program?

   class A {
        int i;
	int j;
        A() {
            i = 1;
            j = 2;
        }
   }
   class Output {
        public static void main(String args[])
        {
             A obj1 = new A();
	     System.out.print(obj1.toString());
        }
   }
A. true
B. false
C. String associated with obj1
D. Compilation Error

2

What is the output of this program?

    class output {
        public static void main(String args[])
        {
             String chars[] = {"a", "b", "c", "a", "c"};
             for (int i = 0; i < chars.length; ++i)
                 for (int j = i + 1; j < chars.length; ++j)
                     if(chars[i].compareTo(chars[j]) == 0)
                         System.out.print(chars[j]); 
        }
   }
A. ab
B. bc
C. ca
D. ac

3

What is the output of this program?

    class String_demo {
        public static void main(String args[])
        {
            char chars[] = {'a', 'b', 'c'};
            String s = new String(chars);
            String s1 = "abcd";
            int len1 = s1.length();
            int len2 = s.length();
            System.out.println(len1 + " " + len2);
        }
   }
A. 3 0
B. 0 3
C. 3 4
D. 4 3

4

What is the output of this program?

 
    class output {
        public static void main(String args[])
        {
            char ch;
            ch = "hello".charAt(1);
            System.out.println(ch);
        }
   }
A. h
B. e
C. l
D. o

5

What is the output of this 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);
 
        }
   }
A. 4 8
B. 5 9
C. 4 9
D. 5 8