Java, matrix

Java, matrix

java program to get output on the basis of users choice of switch statement perform operations addition, subtraction and multiplication of matrix.

View Answers

October 28, 2012 at 3:06 PM

import java.io.*;
class Matrix
        {
            int a ,b,i,j;
        int matrix[][]=new int [12][14];
        void Read()
            {
                int a ,b,i,j;
        int matrix[][]=new int [12][14];    
            DataInputStream is=new DataInputStream(System.in);
            try
            {
            System.out.println("enter the row");
            a=Integer.parseInt(is.readLine());
            System.out.println("enter the col;umn");
            b=Integer.parseInt(is.readLine());
            System.out.println("enter the elements for the matrix");
            for(i=0;i<a;i++)
                    {
                    for(j=0;j<b;j++)
                            {
                            matrix[i][j]=Integer.parseInt(is.readLine());
                            }
                            }


                System.out.println("the matrix that you entered is");

                for(i=0;i<a;i++)
                    {
                    for(j=0;j<b;j++)
                            {
                        System.out.print(matrix[i][j]);
                            }
                        }
            }
                        catch(Exception ex)
                        {}
            }
                public static void main(String args[])
                {
                Matrix m=new Matrix();
                m.Read();
                }
                }

October 29, 2010 at 3:27 PM

Hello Friend,

Try this:

import java.util.*;
class MatrixExamples{

    public static void main(String[] args){
    Scanner input = new Scanner(System.in);
    int[][] A = new int[2][2];
int[][] B = new int[2][2];
int[][] C = new int[2][2];
System.out.println("Enter elements for matrix A : ");
for (int i=0 ; i < A.length ; i++)
for  (int j=0 ; j < A[i].length ; j++){
A[i][j] = input.nextInt();
}
System.out.println("Enter elements for matrix B : ");
for (int i=0 ; i < B.length ; i++)
for  (int j=0 ; j < B[i].length ; j++){
B[i][j] = input.nextInt();
}
System.out.println("Matrix A: ");
        for (int i=0 ; i < A.length ; i++)
        {     System.out.println();
            for  (int j=0 ; j < A[i].length ; j++){
                System.out.print(A[i][j]+" ");
                  }
        }
System.out.println();
System.out.println("Matrix B: ");
        for (int i=0 ; i < B.length ; i++)
        {     System.out.println();
            for  (int j=0 ; j < B[i].length ; j++){
                System.out.print(B[i][j]+" ");
                  }
        }
System.out.println();
int menu = 0;
System.out.println();
System.out.println("1. Addition Of Matrix");
System.out.println("2. Subtraction Of Matrix");
System.out.println("3. Multiplication Of Matrix");
System.out.println("4. Exit");
boolean quit = false;
do{
System.out.print("Please enter your choice: ");
menu = input.nextInt();
System.out.println();

switch(menu) {
case 1:
    System.out.println("*Sum of 2 matrices*");
    for(int i=0;i<2;i++){
for(int j=0;j<2;j++){
C[i][j]=A[i][j]+B[i][j];
System.out.print(C[i][j]+" ");
}
System.out.println();
}
break;
case 2:
    System.out.println("Subtraction of 2 matrices*");
    for(int i=0;i<2;i++){
for(int j=0;j<2;j++){
C[i][j]=A[i][j]-B[i][j];
System.out.print(C[i][j]+" ");
}
System.out.println();
}
break;
case 3:
System.out.println("*Multiplication of 2 matrices*");

for(int i=0;i<2;i++)
{
for(int j=0;j<2;j++)
{
for(int k=0;k<2;k++)
{

C[i][j]+=A[i][k]*B[k][j];

}
}
}

for(int i=0;i<2;i++)
{
for(int j=0;j<2;j++)
{
System.out.print(+C[i][j]+" ");
}
System.out.println();
} 
break;
case 4:
quit = true;
break;
default:
System.out.println("Invalid Entry!");
 }
}
while (!quit);
}
}

Thanks


October 28, 2012 at 3:06 PM

import java.io.*;
class Matrix
        {
            int a ,b,i,j;
        int matrix[][]=new int [12][14];
        void Read()
            {
                int a ,b,i,j;
        int matrix[][]=new int [12][14];    
            DataInputStream is=new DataInputStream(System.in);
            try
            {
            System.out.println("enter the row");
            a=Integer.parseInt(is.readLine());
            System.out.println("enter the col;umn");
            b=Integer.parseInt(is.readLine());
            System.out.println("enter the elements for the matrix");
            for(i=0;i<a;i++)
                    {
                    for(j=0;j<b;j++)
                            {
                            matrix[i][j]=Integer.parseInt(is.readLine());
                            }
                            }


                System.out.println("the matrix that you entered is");

                for(i=0;i<a;i++)
                    {
                    for(j=0;j<b;j++)
                            {
                        System.out.print(matrix[i][j]);
                            }
                        }
            }
                        catch(Exception ex)
                        {}
            }
                public static void main(String args[])
                {
                Matrix m=new Matrix();
                m.Read();
                }
                }

October 28, 2012 at 3:06 PM

import java.io.*;
class Matrix
        {
            int a ,b,i,j;
        int matrix[][]=new int [12][14];
        void Read()
            {
                int a ,b,i,j;
        int matrix[][]=new int [12][14];    
            DataInputStream is=new DataInputStream(System.in);
            try
            {
            System.out.println("enter the row");
            a=Integer.parseInt(is.readLine());
            System.out.println("enter the col;umn");
            b=Integer.parseInt(is.readLine());
            System.out.println("enter the elements for the matrix");
            for(i=0;i<a;i++)
                    {
                    for(j=0;j<b;j++)
                            {
                            matrix[i][j]=Integer.parseInt(is.readLine());
                            }
                            }


                System.out.println("the matrix that you entered is");

                for(i=0;i<a;i++)
                    {
                    for(j=0;j<b;j++)
                            {
                        System.out.print(matrix[i][j]);
                            }
                        }
            }
                        catch(Exception ex)
                        {}
            }
                public static void main(String args[])
                {
                Matrix m=new Matrix();
                m.Read();
                }
                }









Related Tutorials/Questions & Answers:
Java, matrix
Java, matrix  java program to get output on the basis of users choice... of matrix.   Hello Friend, Try this:ADS_TO_REPLACE_1 import... for matrix A : "); for (int i=0 ; i < A.length ; i++) for (int j=0 ; j < A[i
Parallel multiplication matrix in java
Parallel multiplication matrix in java  hello dear I need parallel multiply matrix in java algorithm to account speed up and efficiency great wishes
Advertisements
matrix calculator - Java Beginners
matrix calculator  hi..... can you help me in writing source code of matrix calculator in java... i know you are the best you can do it!!! show yourself
matrix determination in java
matrix determination in java  hai
Matrix Addition using RMI in Java
Matrix Addition using RMI in Java  Source Code for Matrix Addition using RMI in Java
Matrix - Java Beginners
Matrix  give me the Matrix program   Hi friend, Code for Matrix Example in Java class MatrixExample{ public static void main...(" ]"); } System.out.println(); } } For more information on java visit to : http
code for multiplication of matrix in java using methods
code for multiplication of matrix in java using methods  code for multiplication of matrix in java using methods
matrix adddition
matrix adddition   how to write a program matrix addition in java
how to create unit matrix in java of arbritary dimensions
how to create unit matrix in java of arbritary dimensions  i want to create the unit matrix of arbritary dimensions say (n*m).i m a new beginner to java.someone having the program for that? help would be appreciable
Java Transpose of a matrix
Java Transpose of a matrix In this section, you will learn how to determine the transpose of a matrix.The transpose of a matrix is formed by interchanging the rows and columns of a matrix such that row i of matrix becomes column i
Matrix Multiplication in Java
Matrix Multiplication in Java In this Java tutorial we will demonstrate you 'Matrix Multiplication in Java' with the help of a simple example from which you can easily learn how to write a matrix multiplication program in Java
Find sum of all the elements of matrix using Java
Find sum of all the elements of matrix using Java A matrix is a rectangular array of numbers. The numbers in the matrix are called its entries or its elements. A matrix with m rows and n columns is called m-by-n matrix or m × n matrix
Dividing of two Matrix in Java
Dividing of two Matrix in Java   ...;Here you will learn how to use two matrix array for developing Java program.  The java two dimensional array program is operate the two matrix. Now we
how to make a matrix like datagrid in ide in java pls help
how to make a matrix like datagrid in ide in java pls help  how to make a datagrid mainly matrix in ajava standalone app
Matrix Example in Java
Matrix Example in Java       In Java tutorial, you will learn about array and matrix. An array... int data type. Matrix: A matrix is a collection of data in rows and columns
Java create Identity matrix
Java create Identity matrix In this tutorial, you will learn how to create an identity or unit matrix. An identity matrix is a square matrix, of size n x n... elements are zeros. Here, we are going to create the unit matrix of arbitrary
determinant of n*n matrix using java code
determinant of n*n matrix using java code  Here is my code... Scanner(System.in); System.out.println("enter dimension of matrix"); N...]; } System.out.println("enter the elements of matrix"); for(int i=0;i<N;i
Display tow dimensional array by matrix form using one for loop in java
Display tow dimensional array by matrix form using one for loop in java  Display tow dimensional array by matrix form using one for loop in java
want to display the follwing matrix format - Java Beginners
want to display the follwing matrix format  Hi frends, Actually i was working on the following matrix format........I neeed to use arraylist... gives 3 then he should get 3*3 matrix with folllowing data, and when user gives 4
matrix addition
matrix addition  hai
matrix substraction
matrix substraction  hai
matrix substraction
matrix substraction  hai
matrix addition
matrix addition  hai
transpose matrix
transpose matrix  write a program in java to declare a square... integers into the matrix and print the transpose of it. for this program u r given answer but if i entered 2 by 3 matrix it will not give answer ple check it once
Magic Matrix in GUI
Magic Matrix in GUI  I want program in java GUI contain magic matrix for numbers
finding the eigenvalues and eigenvector of n*n matrix in java
finding the eigenvalues and eigenvector of n*n matrix in java  Here...[][] {{4,3,1,2},{1,1,1,1},{1,2,1,1},{1,1,1,1} }; double t, c, s; int p, q, icount... = new double[2][2]; // makes V into a unit matrix V = new double[size][size
transpose of matrix
transpose of matrix  write a program in java to declare a square matrices 'A' or order n which is less than 20.allow in user to input only positive integers into the matrix and print the transpose
column matrix
column matrix  columan wise total matrix
column matrix
column matrix  columan wise total matrix
how to find the eigenvalue and eigenvector of n*n matrix in java
how to find the eigenvalue and eigenvector of n*n matrix in java  I m the new beginner in java and want to find eigenvalue and eigenvector of n*n matrix.where n is vary from n=4,5,6...... pls help me that would be appreciable
Matrix multiplication
Matrix multiplication  program to read the elements of the given two matrices of order n*n and to perform the matrix multiplication
how to enter matrix data into a table of swings - Java Beginners
how to enter matrix data into a table of swings   Hi frends, I want to display a matrix data into a particular table...... Actually if the user input is 3*3 matrix and he got the matrix then it should create 3*3 table
Find determinant of a matrix in Java Programming
Find determinant of a matrix in Java Programming A determinant is a real number associated with every square matrix or, you can say it is a rectangular array... for measure when the matrix is regarded as a linear transformation. Here we
Matrix Class
Matrix Class   A class to manage matrices and add them. Create in the driver class two objects of it and use the add method
Matrix Class
Matrix Class   A class to manage matrices and add them. Create in the driver class two objects of it and use the add method
Multiplication of two Matrix
. The Java two dimensional array  program is operate to the two matrix number... Multiplication of Two Matrix       This is a simple Java multidimensional array program
parallel dense matrix multiplication
using dense parallel matrix multiplication. I request you to kindly provide me a code for Parallel Matrix multiplication on distributed systems using Java...parallel dense matrix multiplication  hi friends, i am a final year
matrix polynamial addtion
matrix polynamial addtion  hai
Matrix multiplication in java
Matrix multiplication in java In this section we will learn about multiplication of two matrices. In java this is a simple program to multiply two matrices... for the second matrix q = in.nextInt(); // q holding
matrix
Multiplication of two Matrix
;    This is a simple java program that teaches you for multiplying two matrix to each other. Here providing you Java source code with understanding the Java developing application program. We are going to make a simple
Maven dependency for com.vwkit - matrix-boot-starter-based version 1.5.3 is released. Learn to use matrix-boot-starter-based version 1.5.3 in Maven based Java projects
? Steps to use  com.vwkit - matrix-boot-starter-based version 1.5.3 in Java...Maven dependency for  com.vwkit  - Version 1.5.3 of matrix-boot-starter-based released The developers of   com.vwkit - matrix-boot
Maven dependency for com.vwkit - matrix-boot-starter-based version 1.5.1 is released. Learn to use matrix-boot-starter-based version 1.5.1 in Maven based Java projects
? Steps to use  com.vwkit - matrix-boot-starter-based version 1.5.1 in Java...Maven dependency for  com.vwkit  - Version 1.5.1 of matrix-boot-starter-based released The developers of   com.vwkit - matrix-boot
Maven dependency for com.vwkit - matrix-boot-starter-based version 1.5.4 is released. Learn to use matrix-boot-starter-based version 1.5.4 in Maven based Java projects
? Steps to use  com.vwkit - matrix-boot-starter-based version 1.5.4 in Java...Maven dependency for  com.vwkit  - Version 1.5.4 of matrix-boot-starter-based released The developers of   com.vwkit - matrix-boot
Maven dependency for com.vwkit - matrix-boot-starter-based version 1.5.2 is released. Learn to use matrix-boot-starter-based version 1.5.2 in Maven based Java projects
? Steps to use  com.vwkit - matrix-boot-starter-based version 1.5.2 in Java...Maven dependency for  com.vwkit  - Version 1.5.2 of matrix-boot-starter-based released The developers of   com.vwkit - matrix-boot
Maven dependency for com.vwkit - matrix-boot-starter-based version 1.4.0 is released. Learn to use matrix-boot-starter-based version 1.4.0 in Maven based Java projects
? Steps to use  com.vwkit - matrix-boot-starter-based version 1.4.0 in Java...Maven dependency for  com.vwkit  - Version 1.4.0 of matrix-boot-starter-based released The developers of   com.vwkit - matrix-boot
Maven dependency for com.vwkit - matrix-boot-starter-based version 1.4.1 is released. Learn to use matrix-boot-starter-based version 1.4.1 in Maven based Java projects
? Steps to use  com.vwkit - matrix-boot-starter-based version 1.4.1 in Java...Maven dependency for  com.vwkit  - Version 1.4.1 of matrix-boot-starter-based released The developers of   com.vwkit - matrix-boot
Maven dependency for com.vwkit - matrix-boot-starter-based version 1.4.3 is released. Learn to use matrix-boot-starter-based version 1.4.3 in Maven based Java projects
? Steps to use  com.vwkit - matrix-boot-starter-based version 1.4.3 in Java...Maven dependency for  com.vwkit  - Version 1.4.3 of matrix-boot-starter-based released The developers of   com.vwkit - matrix-boot
Maven dependency for com.vwkit - matrix-boot-starter-based version 1.4.2 is released. Learn to use matrix-boot-starter-based version 1.4.2 in Maven based Java projects
? Steps to use  com.vwkit - matrix-boot-starter-based version 1.4.2 in Java...Maven dependency for  com.vwkit  - Version 1.4.2 of matrix-boot-starter-based released The developers of   com.vwkit - matrix-boot
Maven dependency for com.vwkit - matrix-boot-starter-based version 1.5.0 is released. Learn to use matrix-boot-starter-based version 1.5.0 in Maven based Java projects
? Steps to use  com.vwkit - matrix-boot-starter-based version 1.5.0 in Java...Maven dependency for  com.vwkit  - Version 1.5.0 of matrix-boot-starter-based released The developers of   com.vwkit - matrix-boot

Ads