Page 400 - CA_Blue( J )_Class10
P. 400
30 for (i=0; i<l2; i++)
31 { ar3[j]=ar2[i]; j++; }
32 System.out.print("Merged Array ");
33 for (i=0; i<l3; i++)
34 { System.out.print(ar3[i]+ ":" ); }
35 }
36 }
You will get the following output:
Enter length of 1st array : 3
Enter length of 2nd array : 2
Length of merged array
Enter element in 1st array : 10
Enter element in 1st array : 20
Enter element in 1st array : 30
Enter element in 2nd array : 40
Enter element in 2nd array : 50
Merged Array 10:20:30:40:50:
Program 18 To display the elements of two-dimensional array in a matrix format.
1 import java.util.Scanner;
2 public class TwoDimensionalArray {
3 public static void main(String[] args) {
4 Scanner scanner = new Scanner(System.in);
5
6 // Declaration of the two-dimensional array
7 System.out.print("Enter the number of rows: ");
8 int rows = scanner.nextInt();
9 System.out.print("Enter the number of columns: ");
10 int cols = scanner.nextInt();
11
12 // Initialization of the two-dimensional array
13 int[][] matrix = new int[rows][cols];
14
15 // Accepting data into the array
16 System.out.println("Enter the elements of the matrix:");
17 for (int i = 0; i < rows; i++) {
398398 Touchpad Computer Applications-X

