# input using scanner and add/sub/mul/div of a matrix

bhagirath singh
input using scanner and add/sub/mul/div of a matrix
1 Answer(s)      6 years and 2 months ago
Posted in : Java Beginners

hiiii...... performe matrix add/sub/mul/div using scanner.

March 5, 2011 at 11:09 AM

Java Matrix Calculation

```import java.util.*;
class MatrixExamples{

public static void main(String[] args){
Scanner input = new Scanner(System.in);
int[][] A = new int[3][3];
int[][] B = new int[3][3];
int[][] C = new int[3][3];
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();
System.out.println();
System.out.println("2. Subtraction Of Matrix");
System.out.println("3. Multiplication Of Matrix");
System.out.println("4. Division Of Matrix");
System.out.println("5. Exit");
boolean quit = false;
do{
System.out.println();

case 1:
System.out.println("Sum of 2 matrices");
for(int i=0;i<3;i++){
for(int j=0;j<3;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<3;i++){
for(int j=0;j<3;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<3;i++){
for(int j=0;j<3;j++){
for(int k=0;k<3;k++){
C[i][j]+=A[i][k]*B[k][j];
}
}
}
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
System.out.print(+C[i][j]+" ");
}
System.out.println();
}
break;
case 4:
System.out.println("Division of 2 matrices : ");
for(int i = 0; i < 3; i++) {
for(int j = 0; j < 3; j++) {
C[i][j]=A[i][j]/B[i][j];
System.out.print(C[i][j]+" ");
}
System.out.println(" ");
}
case 5:
quit = true;
break;
default:
System.out.println("Invalid Entry!");
}
}
while (!quit);
}
}
```

input using scanner and add/sub/mul/div of a matrix
input using scanner and add/sub/mul/div of a matrix  hiiii...... performe matrix add/sub/mul/div using scanner
Find sum of all the elements of matrix using Java
[][] matrix; Scanner input = new Scanner(System.in); System.out.print("Enter number...Find sum of all the elements of matrix using Java A matrix is a rectangular... of matrix and add each element of the matrix to the variable sum. Finally
Matrix Addition using RMI in Java
Matrix Addition using RMI in Java  Source Code for Matrix Addition using RMI in Java
Scanner
Scanner   Hi, I am facing a problem in the following code as what...= "Celsius"; do { Scanner temp_ip= new Scanner(System.in... { System.out.println("Invalid Input. Try Again!!!"); } } while
with out using scanner mul two matrices
with out using scanner mul two matrices  write a java program to multiply two matrices and print there result. note: don't use the scanner...]; System.out.println("Enter elements for matrix A : "); for (int i=0 ; i
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
determinant of n*n matrix using java code
determinant of n*n matrix using java code  Here is my code... { double A[][]; double m[][]; int N; public input() { Scanner s=new Scanner(System.in); System.out.println("enter dimension of matrix"); N
Creating a File I/O using import scanner, io.* and text.*
Creating a File I/O using import scanner, io.* and text.*  open a file for reading and open another file for writing data. input file hours-int, hourly rate-double, name-string. output file name-string, hours-int, hourly rate
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
Java file scanner
Java file scanner In this section, you will learn how to read a file using Scanner class. Description of code: J2SE5.0 provides some additional classes and methods that has made the programming easier. In comparison to any input
can we use scanner class,class , object and methods to get output without using constructor ????
can we use scanner class,class , object and methods to get output without using constructor ????  im getting error here..i hav used scanner class... am i getting error here... can we get output using scanner class , object
How to take input by user using jDialogue and use that input
How to take input by user using jDialogue and use that input  I am using NetBeans i have a 'Search by employee id' button . I want when user click this button a dialogue box appear which take employee_id as input from user
Scanner class
Scanner class  import java.util.*; class Dd { public static void main(String args[]) { Scanner sc=new Scanner(System.in); int...; Here your code works fine..Which java version you are using? Actually
scanner program
his profit..using scanner...scanner program  a news paper boy purchase 100 papers every day.he purchases papers at Rs.1.50 and sells at Rs.2.00 at each.any unsold news papers
Scanner class
Scanner class  what have to do when an error occur about Scanner class.i code scanner sc=new Scanner(System.in); but it shows an error regarding this.   Use Scanner sc=new Scanner(System.in
Java, matrix
of matrix.   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
without scanner
attributes : name , age , salary and note that we need to solve it using array and class and didn't use the scanner .   Hi Friend, Whether
Java Transpose of a matrix
Exception { int rows, cols; int[][] matrix, tmatrix; Scanner input = new... to create a matrix. Then using the for loop statements, turn all the rows...Java Transpose of a matrix In this section, you will learn how to determine
transpose matrix
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 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
matrix substraction
matrix substraction  hai
matrix substraction
matrix substraction  hai
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
scanner - Java Beginners
scanner   how to ask user to enter index in arry using scanner
input
input  a java program that will exchange the last names of two students that were input by a user
column matrix
column matrix  columan wise total matrix
column matrix
column matrix  columan wise total matrix
Matrix multiplication
Matrix multiplication  program to read the elements of the given two matrices of order n*n and to perform the matrix multiplication
Tutorials