Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
3 views6 pages

Single Dimension Arrays

The document contains a series of output-based questions related to single dimension arrays in Java, covering topics such as sorting algorithms, array initialization, and assertions. Each question presents code snippets and multiple-choice answers to test understanding of array behavior and Java syntax. Additionally, it includes assertions and reasoning questions that require evaluating the truth of statements about arrays and their properties.
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)
3 views6 pages

Single Dimension Arrays

The document contains a series of output-based questions related to single dimension arrays in Java, covering topics such as sorting algorithms, array initialization, and assertions. Each question presents code snippets and multiple-choice answers to test understanding of array behavior and Java syntax. Additionally, it includes assertions and reasoning questions that require evaluating the truth of statements about arrays and their properties.
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/ 6

CMS, Indira Nagar Campus-I, Lucknow

CLASS-X (COMPUTER APPLICATIONS)


Single Dimension Arrays

OUTPUT BASED QUESTIONS


Question 1
Following is the code for sorting an array arr having 10 integer elements in ascending order using
Bubble Sort technique:
Line 1: for (i=0;i<9;i++)
Line 2: for (j=0 ; j < 9 - i ; j++)
Line 3: if (arr[j]>arr[j+1]){
Line 4: tmp=arr[j];
Line 5: arr[j]=arr[j+1];
Line 6: arr[j+1]=tmp;
Line 7: }

What would be the impact on the output if the Line 2 above (marked in yellow) in the code is
replaced with the below line:
for (j=0 ; j < 9 ; j++)
a) Array will now get sorted in descending order
b) Index out of bound error during run time
c) Array elements will not be sorted
d) Array will still get sorted in ascending order
Question 2
What is the output of the following code snippet:
int x[] = {0,1,2};
int y[] = {3,4,5};
System.out.println((x[0]=x[1]*x[2])+(y[0]=y[1]*y[2]));

a) 0 3
b) 0 1 2 3 4 5
c) 22
d) Compilation Error
Question 3
What is the output of the following code snippet:
float x[] = {3.14f,3.15f,3.16f};
double y[] = {3.15,3.14,3.16};System.out.println(x[0]>y[1]);
System.out.println(x[1] == y[0]);

a) false
false

b) false
true

c) true
false

d) true
true
Question 4
What is the output of the following code snippet:
int x=0,y=0;
int z[]={3,5,-4};
z[0]+=z[1]-=z[2];
System.out.println(z[0]);
System.out.println(z[1]);

a) Compilation Error

b) 3
5

c) 8
1

d) 12
9

e) -4
-4

Question 5
What is the output of the following code snippet:
public static void main()
{
int A[] = {13, 4, 5, 6, 7, 8};
if (A[0] > A[1])
{
System.out.println("India");
break;
}
else
System.out.println("Delhi");
System.out.println("Goa");
}
}
a) Delhi
Goa

b) India
Goa

c) India
d) Compilation Error
Question 6
Identify the incorrect array initialization:
a) int [] num1 = {3,14,19,4,38,5};
b) int num2[]={1,2,3,4,5};
c) int [] num3 = new int []{3,14,19,4,38,5};
d) None of the above

Question 7
In Java arrays are:
a) Objects
b) Object references
c) Primitive data types
d) None of the above

Question 8
What is the output of the following code snippet:
int a[] = new int[0];
System.out.println(a.length);

a) 0
b) Compilation error, arrays cannot be initialized to zero size.
c) Compilation error, it is a.length() not a.length
d) None of the above

Question 9
What is the output of the following code snippet:
int []x = new int[3];
System.out.println("x[0] is: " + x[0]);

a) The program has a compile error because the size of the array wasn't specified when
declaring the array.
b) The program has a runtime error because the array elements are not initialized.
c) The program runs fine and displays x[0] is 0.
d) The program has a runtime error because the array element x[0] is not defined.

Question 10
What is the output of the following code snippet:
intarr [] = new int[10];
for (inti = 0; i< 10; ++i)
{
arr[i] = i;
System.out.print(arr[i] + " ");
i++;
}

a) 02468
b) 13579
c) 0123456789
d) 1 2 3 4 5 6 7 8 9 10

Question 11
What is the output of the following code snippet:
intarr[] = new int[] {0 , 1, 2, 3, 4, 5, 6, 7, 8, 9};
int n = 6;
n = arr[arr[n] / 2];
System.out.println(arr[n] / 2);

a) Compilation Error
b) 3
c) 6
d) 1

Question 12
What is the output of the following code snippet:
int []a, x, y;
x = Math.max(-1, -2);
y = Math.min(-1, -3);
System.out.println(x + y);

a) -3
b) -4
c) -5
d) Compilation Error

ASSERTION AND REASONING

Question 1
Assertion (A): The index of last element of an array is equal to the number of elements in the array.
Reason(B): Index of an array begins from 0
a) Both Assertion(A) and Reason (R) are true and Reason(R) is correct explanation of Assertion
(A).
b) Both Assertion(A) and Reason (R) are true and Reason(R) is not correct explanation of
Assertion (A).
c) Assertion (A) is true and Reason(R) is false.
d) Assertion (A) is false and Reason (R) is true.

Question 2
Assertion (A): Exchange Selection Sort sorts an array by repeatedly finding the minimum element
(considering ascending order) from the unsorted part and putting it at the beginning..
Reason(B): Exchange Selection Sort maintains three subarrays in a given array.
a) Both Assertion(A) and Reason (R) are true and Reason(R) is correct explanation of Assertion
(A).
b) Both Assertion(A) and Reason (R) are true and Reason(R) is not correct explanation of
Assertion (A).
c) Assertion (A) is true and Reason(R) is false.
d) Assertion (A) is false and Reason (R) is true.

Question 3
Assertion (A): An array is a series of elements of the same type and these elements are placed in
contiguous memory locations.
Reason(B): An array is a series of elements of the same type and these elements are placed in non-
contiguous memory locations.
a) Both Assertion(A) and Reason (R) are true and Reason(R) is correct explanation of Assertion
(A).
b) Both Assertion(A) and Reason (R) are true and Reason(R) is not correct explanation of
Assertion (A).
c) Assertion (A) is true and Reason(R) is false.
d) Assertion (A) is false and Reason (R) is true.
Question 4
Assertion (A): Arrays are objects in java.
Reason(B): The use of new operator is compulsory to initialize an array.
a) Both Assertion(A) and Reason (R) are true and Reason(R) is correct explanation of Assertion
(A).
b) Both Assertion(A) and Reason (R) are true and Reason(R) is not correct explanation of
Assertion (A).
c) Assertion (A) is true and Reason(R) is false.
d) Assertion (A) is false and Reason (R) is true.
Question 5
Assertion (A): The size of the array cannot be altered (once initialized)
Reason(B): Like Strings arrays in java are immutable.
a) Both Assertion(A) and Reason (R) are true and Reason(R) is correct explanation of Assertion
(A).
b) Both Assertion(A) and Reason (R) are true and Reason(R) is not correct explanation of
Assertion (A).
c) Assertion (A) is true and Reason(R) is false.
d) Assertion (A) is false and Reason (R) is true

Question 6
Assertion (A): Binary search is fast compared to Linear Search
Reason(B): Binary Search repeatedly divides the search interval in half.
a) Both Assertion(A) and Reason (R) are true and Reason(R) is correct explanation of Assertion
(A).
b) Both Assertion(A) and Reason (R) are true and Reason(R) is not correct explanation of
Assertion (A).
c) Assertion (A) is true and Reason(R) is false.
d) Assertion (A) is false and Reason (R) is true
Question 7
Assertion (A): Binary search works on sorted array.
Reason(B): Linear Search works on both sorted as well as unsorted array.
a) Both Assertion(A) and Reason (R) are true and Reason(R) is correct explanation of Assertion
(A).
b) Both Assertion(A) and Reason (R) are true and Reason(R) is not correct explanation of
Assertion (A).
c) Assertion (A) is true and Reason(R) is false.
d) Assertion (A) is false and Reason (R) is true
Question 8
Assertion (A): The statement double arr[] = new double[10] reserves 80 bytes of memory space.
Reason(B): The size of double data type is 8 bytes.
a) Both Assertion(A) and Reason (R) are true and Reason(R) is correct explanation of Assertion
(A).
b) Both Assertion(A) and Reason (R) are true and Reason(R) is not correct explanation of
Assertion (A).
c) Assertion (A) is true and Reason(R) is false.
d) Assertion (A) is false and Reason (R) is true
Question 9
Assertion (A): Linear search and Binary search are the searching techniques for searching an
element in an array.
Reason(B): Binary search can be applied on unsorted elements of an array.
a) Both Assertion(A) and Reason (R) are true and Reason(R) is correct explanation of Assertion
(A).
b) Both Assertion(A) and Reason (R) are true and Reason(R) is not correct explanation of
Assertion (A).
c) Assertion (A) is true and Reason(R) is false.
d) Assertion (A) is false and Reason (R) is true
Question 10
Assertion (A): The output of the below two lines of java code will be 0.
Int arr[]= new int [10];
System.out.println(arr[2]);
Reason(B): Default value of int variable is 0
a) Both Assertion(A) and Reason (R) are true and Reason(R) is correct explanation of Assertion
(A).
b) Both Assertion(A) and Reason (R) are true and Reason(R) is not correct explanation of
Assertion (A).
c) Assertion (A) is true and Reason(R) is false.
d) Assertion (A) is false and Reason (R) is true

You might also like