Experiment 3 Java Prachi
Experiment 3 Java Prachi
AIM:Program in Arrays
1D array
To search an given element in the Array. To merge two arrays.
2D arrays
To check if the entered matrix is symmetric or not. To perform Matrix Multiplication
To find out trace and Norm of a particular Matrix.
OBJECTIVE : To make students understand the basics of Arrays in Java and their major
difference with
Arrays in C
Description :
Write the following about both 1D and 2D arrays : What are arrays in General.
Syntax of array declaration, creation and initialization
Static and dynamic initialization methods
Default initialisation
Write about arraycopy method(refer book of authorThampi) and Length Atribute
Difference between arrays in c and java
import java.util.Scanner;
int[] numbers = {10, 20, 30, 40, 50, 60, 70, 80, 90, 100};
scanner.close();
}
}
import java.util.Arrays;
public class MergeArrays {
public static void main(String[] args) {
System.out.println("Prachi Thakare Roll no. 100");
if (isSymmetric(matrix, n)) {
System.out.println("The matrix is symmetric.");
} else {
System.out.println("The matrix is not symmetric.");
}
scanner.close();
}
public static boolean isSymmetric(int[][] matrix, int n) {
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (matrix[i][j] != matrix[j][i]) {
return false;
}
}
}
return true;
}
}
To perform Matrix Multiplication
import java.util.Scanner;
if (colsA != rowsB) {
System.out.println("Matrix multiplication is not possible.");
return;
}
scanner.close();
}
}
To find out trace and Norm of a particular Matrix.
import java.util.Scanner;
scanner.close();
}