# 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 8 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
Read user input in Java using Scanner
Example of of reading user input in Java using Scanner In this section we... input is read using the scanner class. Information entered by user is printed... and Scanner class is one of them. Scanner class can be used to read user input from
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
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
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
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
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
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
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
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
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
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
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
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
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
input
input  a java program that will exchange the last names of two students that were input by a user
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
matrix substraction
matrix substraction  hai
matrix substraction
matrix substraction  hai
How to get the full path location using <input type=file>
How to get the full path location using input type=file  Hi. I have used input type=file> in HTML to select an image. But it selects only the image but not with its full path location. how to do it? Thanks in advance
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 create Identity matrix
main(String[] args) { Scanner input=new Scanner(System.in); System.out.println...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
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
Show text field & check input using jQuery
Show text field & check input using jQuery In this tutorial, we... input using jQuery. In the below example, aIn this tutorial, we will discuss about how to display 'text field' by a button click & check input using
scanner - Java Beginners
scanner   how to ask user to enter index in arry using scanner