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.

View Answers

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();
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. Division Of Matrix");
System.out.println("5. 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<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);
}
}









Related Tutorials/Questions & Answers:
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
Advertisements
Find sum of all the elements of matrix using Java
; int[][] matrix; Scanner input = new Scanner(System.in...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
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
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
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
Java file scanner
Java file scanner In this section, you will learn how to read a file using... in the Scanner's input until it reaches the end of the file. The nextLine() method... input-output stream, we have used Scanner class to read the file.ADS_TO_REPLACE_2
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
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
Java, matrix
){ Scanner input = new Scanner(System.in); int[][] A = new int[2][2]; int[][] B... 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
input
input  a java program that will exchange the last names of two students that were input by a user
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
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
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
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
program to create student report using java applet,read the input using text boxesand generate the grades..?
program to create student report using java applet,read the input using text boxesand generate the grades..?   sir plz give me java applet codes for above question
Java create Identity matrix
static void main(String[] args) { Scanner input=new Scanner(System.in...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
matrix addition
matrix addition  hai
matrix addition
matrix addition  hai
matrix substraction
matrix substraction  hai
matrix substraction
matrix substraction  hai
passing xml created using DocumentBuilderFactory as input to oracle stored procedure using java JDBC
passing xml created using DocumentBuilderFactory as input to oracle stored procedure using java JDBC  I want to send the xml as input parameter to the stored procedure.XML will be created using DocumentBuilderFactory
matrix adddition
matrix adddition   how to write a program matrix addition in java
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
Get the color values as a matrix of color image
Get the color values as a matrix of color image  I am new to java and image processing, i want to get the color values as a matrix from the color image for giving input to the compression algorithm by using java. plz provide
how to enter matrix data into a table of swings - Java Beginners
input is 3*3 matrix and he got the matrix then it should create 3*3 table and insert the data into that table using swings...........matrix can be anything...how to enter matrix data into a table of swings   Hi frends, I
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
Matrix Multiplication in Java
(String args[]) { int m, n, p, q, sum = 0, i, j, k; Scanner... matrix q = in.nextInt(); // q holding the number...Matrix Multiplication in Java In this Java tutorial we will demonstrate you
Java User Input
Java User Input  I am using Scanner class for user Input. Scanner s = new Scanner(System.in); String name = s.next(); but i am unable to store full... nextLine() method of Scanner class
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
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
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
scanner - Java Beginners
scanner   how to ask user to enter index in arry using scanner
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 determination in java
matrix determination in java  hai
matrix polynamial addtion
matrix polynamial addtion  hai
using array
using array  transpose a matrix
using array
using array  transpose a matrix
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,ADS_TO_REPLACE_1
matrix
struts2.2.1 tabular Input example
struts2.2.1 tabular Input example In this example, We will discuss about the Tabular Input validation using struts2.2.1. In this example,We validate the input fields, The Tabular Inputs are used to take the multiple inputs from a form
Magic Matrix in GUI
Magic Matrix in GUI  I want program in java GUI contain magic matrix for numbers

Ads