0% found this document useful (0 votes)
0 views4 pages

Arrays

The document contains a series of multiple-choice questions and programming exercises related to arrays in Java. It covers topics such as array initialization, element access, sorting algorithms, and differences between various array-related concepts. Additionally, it includes questions on debugging and practical programming tasks involving arrays.

Uploaded by

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

Arrays

The document contains a series of multiple-choice questions and programming exercises related to arrays in Java. It covers topics such as array initialization, element access, sorting algorithms, and differences between various array-related concepts. Additionally, it includes questions on debugging and practical programming tasks involving arrays.

Uploaded by

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

Arrays

I Choose the correct answer :


1) int arr[] = {1,2,3,4,5};
for(int i = 0 ; i<5; i++){
System.out.print(arr[i++]);
}
A) 12345 (B) 123 (C) 124 (D) 135

2) int arr[] = {1,2,3,4,5};


for(int i = 0 ; i<5; ){
System.out.print(arr[i]);
}
(A) 12345 (B) Nothing is printed (C) 1 (D) Infinite times

3) int arr[] = {1,2,3,4,5};


int count = 0;
for(int i = 0 ; i<5; i++ ){
if(arr[i]%2==0)
count++;
}
System.out.print(count);
(A) 3 (B) 2 (C) 1 (D) 0

4) int arr[] = {1,2,3,4,5};


int count = 0;
for(int i = 0 ; i<5; i++ ){
if(arr[i]%2==0)
arr[i] *= 2;
System.out.print(arr[i]);
}
(A) 12345 (B) 135 (C) 22222 (D) 14385

5) int arr[] = {'a','b','c','d','e'};


for(int i = 0 ; i<5; i++){
System.out.print(" " + arr[i]);
}
(A) a b c d e (B) abcde (C) 97 98 99 100 101 (D) 65 66 67 68 69

6) int arr[] = {'a','b','c','d','e'};


for(int i = 0 ; i<5; i++){
System.out.print(" "+ (char)arr[i]);
}
(A) a b c d e (B) 96 97 98 99 101 (C) 65 66 67 68 69 (D) None
7) int arr[] = {'a','b','c','d','e'};
System.out.print(arr);

(A) abcde (B) 6566676869 (C) Compilation Error (D) Some Garbage Value

8) char[] a = {'A', 'S', 'I', 'S', 'H'};


int i = 4;
do {
System.out.print(a[i]);
i--;
}while (i>0);

(A) ASISH (B) asish (C) HSISA (D) HSIS

9) int [] array = {1,2,3,4,5};


for(int i = -1; i<5;i++)
System.out.print(array[i]);

(A) 12345 (B) 1234 (C) Compilation Error


(D) ArrayIndexOutOfBoundsException

10) In Java how arrays are passed in methods?


(A) Arrays are passed by Value (B) Arrays are passed by Reference
(C) It depends on type of array (D) It depends on Compiler

11) Which of the following is the correct usage?


(A) int a[-40] (B) int a[40] (C) float a[0 - 40] (D) None

12) Which element is represented by a[10]?


(A) 10th (B) 9th (C)11th (D) None

13) Cell numbers of a dimensional array are also known as:


(A) packets (B) blocks (C) subscripts (D) compartments

14) A dimensional array is also known as:


(A) subscripted variable (B) actual variable
(C) compound variable (D) none

15) An array element can be accessed through:


(A) dots (B) element name (C) index number (D) none
16) The following statement :
int code[ ]= {25,37,38,42};
(A) assigns 37 to code[1] (B) assigns 25 to code[1]
(C) assigns 38 to code[3] (D) assigns 42 to code[0]

17) A Single Dimensional array contains N elements. What will be the last
subscript?
(A) N-1 (B) N (C) N+1 (D) None

II Answer the following questions :

1. What is an array? What are the different types of arrays?


2. Write the syntax to create a string array and store 5 strings in it.
3. Distinguish between length & length()
4. Distinguish between linear search & binary search.
5. Name 2 types of sorting
6. Distinguish between subscript & subscripted variable.
7. Write one advantage and one disadvantage of arrays.
8. In an array A of size 25, A[13] accesses which element?

9. Debug the following:


a) System.out.println(a[5.2]);
b) char [ ]c= new char {‘a’, ‘e’, ‘i’ , ‘o’, ‘u’ };
c) int a[4]={2,4,6,8};
d) byte []arr=new byte[10];

10. Show the vales after each iteration if the following numbers are to be sorted
in ascending order using bubble sort. 3, 11, 2, 18, 5, 6

11. Show the vales after each iteration if the following numbers are to be sorted
in descending order using selection sort. 3,11,2,18,5.6

12. Initialize a string array with days of the week

13. Give the output:

a) char a[]={'h', 'u', 'm', 'a', 'n'};


String s = new String (a);
System.out.println(s);

b) int []a= new int[5];


int i, s=0;
for(i=0; i<5;i++)
a[i]=3*(i+1);
for(i=a.length-1;i>=0;i-=0)
s+=a[i]*a[i];
System.out.println(s),

c) double d[]={3.2,0.5,7.6,8.3};
int p=1:
for( int i=0; i<=d.length-1;i++)
{
P*=(int)Math.floor( d([i]);
System.out.priatln(p);}

14. Answer the following questions regarding an array called real.


a) Define a constant s initialized to 5.
b) Declare an array with s elements of type float.
c) Store elements in the array.
d) Display the second element of the array.
e) Replace the last element of the array by 1.25.

15. Initialise a 3x3 DDA with first 9 natural numbers.

III Answer the following programs :

1. WAP to input roll number, name and marks in 3 subjects of 50 students of a


class. Calculate the percentage marks of each student and print the merit list
using bubble sort.

2. WAP to accept data in a 5x5 matrix and check if it is an identity matrix or not.

************

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy