0% found this document useful (0 votes)
6 views

Array Short Questions

The document contains a series of multiple-choice questions related to Java arrays, covering topics such as array declaration, accessing elements, sorting, and calculating sizes. Each question provides options for answers, testing knowledge of array properties and operations. The questions range from basic concepts to slightly more complex scenarios involving calculations and code snippets.

Uploaded by

arpitaghosh637
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Array Short Questions

The document contains a series of multiple-choice questions related to Java arrays, covering topics such as array declaration, accessing elements, sorting, and calculating sizes. Each question provides options for answers, testing knowledge of array properties and operations. The questions range from basic concepts to slightly more complex scenarios involving calculations and code snippets.

Uploaded by

arpitaghosh637
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

1 What does the given array denoted?

String names[]=new String[10];


a)An array is created with 12 string elements. b) An array is created with 10 string elements
c) This will create an error d) None of these
2 Java statement to access the 5th elements of an array is :
a.x[4] b. x[3] c. x[5] d. x[0]
3 Predict the output 4 What will the vlaue of p result in when:
Char a[]={654,66,67,68,69}; int arr[]={12,5,8,10,11,4};
System.out.println(a[3]); int p=arr.length;
a)68 b) d c) D d) C a)12 b) 6 c) 4 d)0
5 State the number of bytes occupied by a character array of 10 elements
a) 12 bytes b) 18 bytes c) 15 bytes d) 20 bytes
6 What is the index of the 1st elements in an array? a)0 b) 2 c) 1 d) -1
7 Consider the given array and answer the questions given below: int x[]={ 0,7,9,66,72,0,16};
What is the length of the array? What is the value of x[0]?
8 Which of these is an incorrect array declaration?
a) int arr[]=new int[5] b) int [] arr=new int[5] c) int []arr=new int[5] d) int arr[]=int[]5 new
9 Java statement to access the first element of an array x is: a)x[0] b) x[1] c) x[2] d) x[3]
10 Given an integer array {121, 13, 89, 15} what will be the array like after two passes of selection sort, if it to be
arranged in ascending order?a) 121, 13,89,15 b) 13,15,89,121 c) 13,89,15,121 d) 13,15,121,89
11 identity the correct array declaration statement:
a)int a[10]; b) int a[]=new int[10] c) int arr[i]=10 d) int a[10]=new int[];
12 if int n[]={1,3,5,6,7,8,10}; what are the values of p and q? a) p=n.length b) q=n[3]+n[1]* n[5]
13 int P[]={12,14,16,18}; int Q[]={20,22,24};
Place all elements of P array and Q array in the array R one after the other.
a) What will be the size of array R[]? b) Write index position of first and last element of array R[]?
14 Predict the output of the following code snippet: 15)The following code segment should print the sum of all the
Public static void main() one digit integers from an array[] of size 10, However, the code
{ has error, Fix the code so that it compiles and runs correctly.
int a,b=0; Int x[]={4,10,125,6,2,45,66,7,15,12};
int c[]={1,2,3,4,5,6,7,8,910}; Int sum=1;
for(a=0;a<10;a++) For(int i=0;i<x.length;i++)
{ {
if(a%2==0) If(x[i]<=1 && x[i]>=9)
b+=c[a]; Sum=sum+x[i];
} }
System.out.println(b); System.out.print(sum);
}
16 If int n[]={1,2,3,5,7,9,13,16}; what are the values of x and y
X=Math.pow(n[4],n[2]); y=Math.sqrt(n[5]+n[7]);
a) x=343, y=5 b) x=343 , y=6 c) x=335, y=5 d) x=343, y=7
17 Give the output
int a[]={2,4,6,8,19};
a[0]=23;
a[3]=a[1];
int c=a[0]+a[3];
System.out.println(“Sum =”+c);
18 Identify the correct statement from the obpitons given.a) int n[0-9] b) int n[10] c) int n[-9] d) double n[1-10]
19 A single dimensional array contains N elements. What will be the first subscript?
a) N-(N-1) b) N-N c) N-(N+1) d) None of these
20 Total Size of Array a[] having 25 elements of char types is
a) 25 bytes b) 50 bytes c) 100 bytes d) None of these

You might also like