Professional Documents
Culture Documents
Question 1
Output
46
Explanation
Question 2
Output
Sum = 27
Explanation
a[0]=23 assigns 23 to the first element of the array. a[3]=a[1] assigns the value of second
element of the array which is 4 to the fourth element of the array. After the execution of
these two statements array looks like this:
{23, 4, 6, 4, 10}
a[0]+a[1] ⇒ 23 + 4 ⇒ 27
Question 3
Output
12
Explanation
a[2+1] ⇒ a[3] ⇒ 12
Question 4
int a[4]={2,4,6,8};
for(i=0;i<=1;i++)
{
s=a[i]+a[3-i];
System.out.println(s);
}
Output
10
10
Explanation
i Output Remark
a[0] + a[3]
0 ⇒2+8 First Iteration
⇒10
a[1] + a[2]
1 ⇒4+6 Second Iteration
⇒10
Question 1
Question 2
Question 3
Variables are useful for keeping track of a single piece of information but as we
collect more and more information, keeping the variables organized can be
complicated. In such situations, we need arrays to solve the problems in a much
better and efficient way.
Question 4
The data type that represents a number of similar or different data under single
declaration is called as composite data type. An array is a group or a collection of
same type of variables. Hence, Array is a composite data type.
Question 5
A Single Dimensional Array contains one row and one or more columns. The syntax
of declaring a Single Dimensional Array is:
<type> <array-variable>[] = new <type>[<size>];
OR
<type> [] <array-variable> = new <type>[<size>];
(b) Double Dimensional Array
Double Dimensional Array contains multiple rows and multiple columns. The
syntax of declaring a Double Dimensional Array is:
<type> <array-variable>[][] = new <type>[<rows>][<columns>];
OR
<type> [][] <array-variable> = new <type>[<rows>][<columns>];
6. Linear search and Binary search
Linear search works on sorted and Binary search works on only sorted arrays
unsorted arrays (ascending or descending)
length length()
It gives the length of an array i.e. the number of It gives the number of characters
elements stored in an array. present in a string.