81. 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);
}
}
class output
{
public static void main(String args[])
{
String s1 = "Hello World";
String s2 = s1.substring(0 , 4);
System.out.println(s2);
}
}
82. 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);
}
}
class output
{
public static void main(String args[])
{
char ch;
ch = "hello".charAt(1);
System.out.println(ch);
}
}
83. What will be the output of the following Java program?
class String_demo
{
public static void main(String args[])
{
int ascii[] = { 65, 66, 67, 68};
String s = new String(ascii, 1, 3);
System.out.println(s);
}
}
class String_demo
{
public static void main(String args[])
{
int ascii[] = { 65, 66, 67, 68};
String s = new String(ascii, 1, 3);
System.out.println(s);
}
}
84. Which of these is an incorrect statement?
85. 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);
}
}
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);
}
}
86. What is the string contained in s after following lines of Java code?
StringBuffer s new StringBuffer("Hello");
s.deleteCharAt(0);
StringBuffer s new StringBuffer("Hello");
s.deleteCharAt(0);
87. What will be the output of the following Java program?
class output
{
class output
{
public static void main(String args[])
{
char c[]={'A', '1', 'b' ,' ' ,'a' , '0'};
for (int i = 0; i < 5; ++i)
{
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++;
}
}
}
class output
{
class output
{
public static void main(String args[])
{
char c[]={'A', '1', 'b' ,' ' ,'a' , '0'};
for (int i = 0; i < 5; ++i)
{
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++;
}
}
}
88. Which of this method of class String is used to obtain a length of String object?
89. 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;
}
}
}
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;
}
}
}
90. What will be the output of the following Java program?
class output
{
public static void main(String args[])
{
StringBuffer c = new StringBuffer("Hello");
c.delete(0,2);
System.out.println(c);
}
}
class output
{
public static void main(String args[])
{
StringBuffer c = new StringBuffer("Hello");
c.delete(0,2);
System.out.println(c);
}
}
Read More Section(Strings)
Each Section contains maximum 100 MCQs question on Strings. To get more questions visit other sections.