Fall Semester 2024-25 - STS3004 - TH - AP2024252001206 - 2024-10-03 - Reference-Material-I
Fall Semester 2024-25 - STS3004 - TH - AP2024252001206 - 2024-10-03 - Reference-Material-I
● In fact most of the collection types in Java which are the part
of java.util package use arrays internally in their functioning
● Since Arrays are objects, they are created during runtime .The
array length is fixed
FEATURES OF objects
● Arrays are ARRAYS
class ArrayExample {
public static void main(String[] args) {
int[] age = {12, 4, 5, 2, 5};
for (int i = 0; i < 5; ++i) {
System.out.println("Element at index " +
i +": " + age[i]);
}
}
}
PASSING ARRAYS TO METHOD
The above statement creates the array which can hold references
to seven Student objects.
ARRAY OF OBJECTS
The above for loop creates seven Student objects and assigns
their reference to the array elements.
SORTING TECHNIQUES
SORTING TECHNIQUES
BUBBLE SORT
SELECTION SORT
IMPLEMENTING SELECTION SORT
● Repeat the steps above for all remaining elements of the list
starting from the second position.
IMPLEMENTING SELECTION SORT
INSERTION SORT
● Binary Search
LINEAR SEARCH
● Traverse the array
● In each step, the algorithm compares the input key value with the
key value of the middle element of the array.
● If the keys match, then a matching element has been found so its
index, or position, is returned
IMPLEMENTING BINARY SEARCH
2D ARRAY
DECLARATION:
array_name[row_index][column_index] =
value;
For example: arr[0][0] = 1;
ACCESSING 2D ARRAY
Syntax:
x[rowindex][columnindex]
For example:
For example, given the array [2,3,1,2,4,3] and s = 7, the sub array [4,3]
has the minimal of 2 under the problem constraint.
QUESTION 01
A. Objects
B. Object references
C. Primitive data type
D. None of the above
Answer : A
QUESTION 02
class Main A. 50
{ 100
public static void main(String s[]) 100
{ B. 50
int i = 50; 100
int[] a = new int[i]; 100
System.out.println(a.length); C. 50
System.out.println(a.length); 50
System.out.println(a.length); 50
} D. Compilatio
} n Error
Answer : C
QUESTION 06
class Main A. 12
{ 15
public static void 16
main(String s[]) 17
{ 19
int a[] = {12, 15, 16, 17, B. 12
19}; 15
16
for(int i = 0; i < 5; i++) 17 Answer: A
{ C. 15
System.out.println(a[i]); 16
}
17
}
19
}
D. Compilation
error
QUESTION 12
What will be the output of the following program?
a[i] = i;
a[j] = j;
//a[k] = k;
QUESTION 13
What will be the output of the following program?
class Main
A. 1 8 7 4 5 6 3
{
B. 1 8 7 4 5 6 3
public static void main(String s[])
1874563
{
1874563
int list[] = new int[] {1, 8, 7, 4, 5, 6,
1874563
3};
1874563
int count = 1;
C. 1 1 1 1 1 1 1
int copy[][] = new int[list.length][count];
for(int i = 0; i < list.length; i++) 8888888
{ 7777777
copy[i][0] = list[i]; 4444444
for(int j = 0; j < count; j++) D. Compilation Error
{
Answer: A
System.out.print(copy[i][j] + " ");
}
}
System.out.println();
}
}
QUESTION 14
What will be the output of the following program?
class Main
A. 0 1 2
{
B. 0 13
public static void
main(String S[]) C. 3
{ D. 1
for(int i = 0; i E. 1 23
<= 3; i++)
{
if(i == 2)
continue; Answer : B
System.out.println(i);
}
}
}
QUESTION 15