[go: up one dir, main page]

0% found this document useful (0 votes)
89 views5 pages

Java String & Array Quiz

Uploaded by

SUBHANKAR SAHA
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
89 views5 pages

Java String & Array Quiz

Uploaded by

SUBHANKAR SAHA
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

NAME : ___________________________________ TIME : 30 min

1.While using the toLowerCase() method on a string containing special characters, ............... .

1. the special characters remain unaffected.


2. the special characters are converted to spaces.
3. the special characters are converted to null character.
4. the special characters are removed from the string.

2.The trim() method of the String class removes ............... .

1. leading spaces only


2. trailing spaces only
3. spaces in between words
4. leading and trailing spaces

3.The index of a string ............... .

1. ranges from 0 to the length -1 of the string


2. ranges from 0 to the length of the string
3. ranges from 1 to the length of the string
4. ranges from 1 to the length -1 of the string

4.The indexOf() method returns the position of the ............... .

1. first occurrence of the specified character


2. last occurrence of the specified character
3. null character
4. '\n' character

5.The return type of the equals() method is ...............

1. int
2. char
3. boolean
4. void

6.Output of the following statement is ............... .


System.out.println("WONDERFUL".substring(3,4));

1. DERF
2. NDER
3. D
4. N

7.Whayt will be the output -


String arr[]= {"DELHI", "CHENNAI", "MUMBAI", "LUCKNOW", "JAIPUR"};
System.out.println(arr[0].length() > arr[3].length());

1. True
2. False
3. Compile Error
4. 2
8.Give the output of the following string functions:
(i) "ACHIEVEMENT".replace('E', 'A')

Ans :

9."DEDICATE".compareTo("DEVOTE")

1. False
2. True
3. -18
4. 18

10.What will be the output -


String x = "Computer";
String y = "Applications";
System.out.println(x.indexOf(x.charAt(4)));

1. 4
2. p
3. m
4. 3

11.Consider the following program segment and select the output of the same
when n = 10:
switch(n)
{case 10: System.out.print(n*2);
case 4: System.out.print(n*4); break;
default: System.out.println(n);}

1. 2040
2. 104
3. 20,40
4. 1010

12.int x[] = {4,7,9,66,72,0,16};


What is the length of the array?

Ans :

13.Write the value of n after execution:


char ch = ‘d’;
int n = ch + 5;

Ans :

14.The number of bits occupied by the value 'a' are:

1. 1
2. 2
3. 4
4. 16
15.Evaluate the expression when the value of x = 4:
x* = – – x + x + + + x

1. 40
2. 4141
3. 42
4. 10

16.Write will be the output -


System.out.println(Math.sqrt(Math.pow((Math.ceil(5.2)),2)));

1. 6
2. 5
3. 6.0
4. 5.0

17.Give the output of the following program segment:


int n = 4279;
int d;
while(n>0)
{d = n%10;
System.out.print(d);
n = n/100;
}

Ans :

18.What will be the output


String str = "ICSE Computer Applications";
System.out.println(str.startsWith("ICSE"));
System.out.println(str.endsWith("tions"));

Ans :

19.Given array int x[] = {11, 22, 33, 44}; the value of x[1+2] is ........... .

1. 11
2. 22
3. 33
4. 44

20.A binary search -

1. can be used with sorted arrays only


2. can be used with unsorted arrays only
3. can be used with both sorted and unsorted arrays
4. cannot be used with arrays
21.A linear search ...........

1. can be used with sorted arrays only


2. can be used with unsorted arrays only
3. can be used with both sorted and unsorted arrays
4. cannot be used with arrays

22.In ........... search, the algorithm uses the middle value of the array for the search operation.

1. Binary
2. Selection
3. Linear
4. Bubble

23.String str[] = { "Love", "for", "Computer" };


for (int i = 0; i < str.length; i++)
System.out.print(str[i]);

1. LoveforComputer
2. Love
3. forComputer
4. Lovefor

24.What will be the output -


String str[] = { "Love", "for", "Computer" };
System.out.println(str[0].length);

1. 3
2. 4
3. Error
4. 2

25.What will be the output -


int arr[] = { 11, 22, 33 };
System.out.print(arr[-2]);

1. 11 33
2. -11 -22
3. Error
4. Out of bound Exception

26.What will be the output -


int arr[][] = { { 11, 22 }, { 33, 44, 55 } };
for (int i = 0; i < 2; i++) {
for (int j = 0; j < arr.length; j++)
System.out.print(arr[i][j] + " ");

1. 11 22 33 44 55
2. 11 22 33 44
3. 11 33 22 44
4. 11 33 22 44 55
27. What will be the output -
int arr[][] = { { 11, 22 }, { 33, 44, 55 } };
for (int i = 0; i < 2; i++) {
for (int j = 0; j < arr[i].length; j++)
System.out.print(arr[i][j] + " ");

1. 11 22 33 44 55
2. 11 22 33 44
3. 11 33 22 44 55
4. 11 22

28.what will be the output -


long num=729, sum= 0;
for( long y= num; y> 0; y= y/10){
sum= sum + y % 10;
}
System.out.println(sum);

1. 18
2. 72
3. 29
4. 70

29.String str1 = ”great”;


String str2= “Minds”;
System.out.print(str1.substring(0,2).concat(str2.substring(1)));
System.out.print(( “WH”+(str1.substring(2).toUpperCase() )));

1. GREATWHEAT
2. GRINDSWHEAT
3. grindsWHEAT
4. grindsWH

30.What will be the output -


char ch[ ]= {'I', 'N', 'T', 'E', 'L', 'P', 'E', 'N', 'T', 'I', 'U', 'M'};
String obj= new String(ch);
System.out.println(obj);

1. ELPE
2. INTELPENTIUM
3. INTEL
4. PENTIUM

You might also like