51. |
What will be the output of the following Java program?
class output { public static void main(String args[]) { String a = "hello i love java"; System.out.println(a.indexOf('e')+" "+a.indexOf('a')+" "+a.lastIndexOf('l')+" "+a.lastIndexOf('v')); } }
|
||||||||
Answer:
Option (d) |
52. |
What will be the output of the following Java program?
class output { public static void main(String args[]) { StringBuffer c = new StringBuffer("Hello"); StringBuffer c1 = new StringBuffer(" World"); c.append(c1); System.out.println(c); } }
|
||||||||
Answer:
Option (d) |
53. |
What will be the output of the following Java code?
class output { public static void main(String args[]) { StringBuffer sb=new StringBuffer("Hello"); sb.replace(1,3,"Java"); System.out.println(sb); } }
|
||||||||
Answer:
Option (c) |
54. |
What will be the output of the following Java code?
class output { public static void main(String args[]) { StringBuffer s1 = new StringBuffer("Hello"); s1.setCharAt(1,'x'); System.out.println(s1); } }
|
||||||||
Answer:
Option (c) |
55. |
What will be the output of the following Java code?
class output { public static void main(String args[]) { StringBuffer s1 = new StringBuffer("Hello World"); s1.insert(6 , "Good "); System.out.println(s1); } }
|
||||||||
Answer:
Option (d) |
56. |
What will be the output of the following Java program?
class String_demo { public static void main(String args[]) { char chars[] = {'a', 'b', 'c'}; String s = new String(chars); System.out.println(s); } }
|
||||||||
Answer:
Option (d) |
57. |
What will be the output of the following Java code?
class output { public static void main(String args[]) { String c = "Hello i love java"; boolean var; var = c.startsWith("hello"); System.out.println(var); } }
|
||||||||
Answer:
Option (b) |
58. |
What will be the output of the following Java code?
class output { public static void main(String args[]) { String s1 = "Hello"; String s2 = new String(s1); String s3 = "HELLO"; System.out.println(s1.equals(s2) + " " + s2.equals(s3)); } }
|
||||||||
Answer:
Option (c) |
59. |
In the following Java code, which code fragment should be inserted at line 3 so that the output will be: “123abc 123abc”?
1. StringBuilder sb1 = new StringBuilder("123"); 2. String s1 = "123"; 3. // insert code here 4. System.out.println(sb1 + " " + s1);
|
||||||||
Answer:
Option (d) |
60. |
What will be the output of the following Java code?
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]); } }
|
||||||||
Answer:
Option (d) |