Experiment-6: Aim:-Create Java Program With The Use of Java Packages
The document outlines a Java program that creates a package named 'Mathematics' containing a class 'Matrix' for performing addition and subtraction of 2x2 matrices. It includes methods for matrix operations and a main method demonstrating the functionality with example matrices. The program ensures that only 2x2 matrices are accepted and prints the results of the operations.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
4 views2 pages
Experiment-6: Aim:-Create Java Program With The Use of Java Packages
The document outlines a Java program that creates a package named 'Mathematics' containing a class 'Matrix' for performing addition and subtraction of 2x2 matrices. It includes methods for matrix operations and a main method demonstrating the functionality with example matrices. The program ensures that only 2x2 matrices are accepted and prints the results of the operations.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2
Experiment-6
Aim:- Create java program with the use of java packages
Create a package named “Mathematics” and add a class “Matrix” with methods to add and subtract matrices (2x2). Write a Java program importing the Mathematics package and use the classes defined in it.
Code: package package1;
public class Matrix {
private int[][] matrix;
public Matrix(int[][] matrix) {
if(matrix.length!=2 || matrix[0].length!=2 || matrix[1].length!=2) { throw new IllegalArgumentException("Only 2*2 matrices are allowed"); } this.matrix=matrix; }