Java Strings Aptitude Questions and Answers.
Page 2.

List of Java Strings Aptitude Questions

6) What will be the output of following program?
public class temp
{
	public static void main(String args[])
	{
		String text="ABCD";
		byte[] xByte=text.getBytes();
		
		for(byte loop: xByte)
		{
			System.out.print(loop+" ");
		}		
	}
}
  1. A B C D
  2. 41 42 43 44
  3. 65 66 67 68
  4. Error

7) What will be the output by following code snippet?
String text="Hello World, How are you?";
System.out.print(text.lastIndexOf('o'));
System.out.print(" "+text.lastIndexOf('o',5));
  1. 22 4
  2. 22 22
  3. 22 16
  4. None of these

8) What value will be printed after executing following code snippet?
String text="Hello World!";
int index= text.indexOf("llo");
System.out.println(index);
  1. 3
  2. 2
  3. -1
  4. Error

9) What value will be printed after executing following code snippet?
String text="Hello World!";
int index= text.indexOf("hello");
System.out.println(index);
  1. 1
  2. 0
  3. -1
  4. Error

10) What will be the output by following code snippet?
String Str = new String("   Include   Help  ");
System.out.println(Str.trim() );
  1.    Include   Help  
  2. Include   Help
  3.    Include   Help
  4. None of these








Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.