12-ARRAY (1)
12-ARRAY (1)
ARRAY
support@hopeconflict.com
HOPECONFLICT TECHNOLOGY
5. If we take array size with negative value then we will get run time
6. If we are trying to access array element with out of range index we will
Creating An Array :
Syntax :
Example :
Note : Array start with zero location and end with n-1.
support@hopeconflict.com
HOPECONFLICT TECHNOLOGY
Graphical Representation :
Size=size-1
support@hopeconflict.com
HOPECONFLICT TECHNOLOGY
Example :
package arr;
import java.util.Scanner;
elements");
for(int i=0;i<arr.length;i++)
{
arr[i]=sc.nextInt();
}
for(int i=0;i<arr.length;i++)
{
System.out.println(arr[i]);
}
}
support@hopeconflict.com
HOPECONFLICT TECHNOLOGY
TWO DIMENSIONAL ARRAY
Syntax :
graphical representation :
00 01 02
10 11 12
20 21 21
support@hopeconflict.com
HOPECONFLICT TECHNOLOGY
Example :
package ClassWork;
importjava.util.Scanner;
for(int row=0;row<row_size;row++)
{
for(int col=0;col<col_size;col++)
{
matrix1[row][col]=sc.nextInt();
System.out.print(" "+matrix1[row][col]+" ");
}
System.out.println(" ");
}
public static void main(String[] args)
{
MatrixDemo m=new MatrixDemo();
m.matrix();
support@hopeconflict.com
HOPECONFLICT TECHNOLOGY
Advantages :
Disadvantages :
1. Fix in size.
2. Can hold only homogeneous data element only.
3. No in build method support is available for every requirement
Class Work :
1. Write a Java program to calculate the average value of array elements
Output: 4
(1, 1), (1, 2), (2, 1) (2, 2),
Output: 9
5. Calculate the sum of diagonal element of matrix.
support@hopeconflict.com
HOPECONFLICT TECHNOLOGY
Home Work :
0) Write a Java program to sort a numeric array and a char array.
6) WAP to put even and odd elements of array in two separate arrays.
16) Write a Java program to get the difference between the largest and
17) WAP to replace all the 0’s with 1’s in your array. Your array is [26, 0,
integers where all negative integers appear before all the positive
integers
22) Create Student class having rollno, name, marks. Create 10 objects .
24) Given 2 character arrays s1 and s2 and another empty character array s3.
support@hopeconflict.com
HOPECONFLICT TECHNOLOGY
Populate s3 by interleaving characters from both s1 and s1(Mindstix) Method
signature
Void interleaved (char[] s1, char[]s2, char[]s1, int s1_len, int s2_len)
/ Your Code
Example: S1={‘a’,’b’,’c’,’d’};
S2={‘w’,’x’,’y’,’z’};
Output: S1={‘a’,’w’’b’,’x’’c’,’y’,’d’,’z’}.
support@hopeconflict.com
HOPECONFLICT TECHNOLOGY
Interview Questions :
a. What are arrays?
support@hopeconflict.com