Home Answers Viewqa Java-Beginners 17026-input-using-scanner-and-add Sub Mul 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)      2 years and 2 months ago
Posted in : Java Beginners

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 Pages:
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
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
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
Console Input: Scanner
Java NotesConsole Input: Scanner The java.util.Scanner class (added..., closing it would be important. Example using Scanner in a loop 1 2.../ScannerLoop.java // Purpose: Read from the console in a loop using Scanner. // Author
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
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
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
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
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
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 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
Pattern,Matcher,Formatter and Scanner classes
its source. A Scanner converts the input from its source into tokens using... token in this scanner's // input can be interpreted as a boolean value using... using the Formatter and Scanner classes and the PrintWriter.format/printf
scanner - Java Beginners
scanner   how to ask user to enter index in arry using scanner
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
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
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 problem - Java Beginners
scanner problem  the program that enters sides of the triangle using scanner and outputs the area of triangle  Hi Friend, We... main(String []args){ Scanner scanner = new Scanner(System.in
Matrix Addition using RMI in Java
Matrix Addition using RMI in Java  Source Code for Matrix Addition using RMI in Java
Hp scanner - Java Beginners
Hp scanner  Hi guys, i would like to access hp scanner using java programme. could you refer me some useful information to proceed
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
Java Matrix Addition Example
input = new Scanner(System.in); System.out.print("Enter Number of rows...Java Matrix Addition Example In this tutorial, you will learn how to find the sum of two matrices. You may have solved many Matrix Operations in Mathematics
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 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
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
XII STD RECURSION WITHOUT SCANNER
for two input numbers. the code of my program is as follows and the error comes... not wish to use the scanner class Is there anything i can do to improve...( System.in)); System.out.println("Input two nos"); int
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
Java Matrix Subtraction Example
[] args){ Scanner input = new Scanner(System.in); System.out.print("Enter...Java Matrix Subtraction Example In this tutorial, you will learn how to find... and then accept the matrix elements as array elements. We have declared two
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
The BCG Matrix
The BCG matrix also called the Growth share matrix, B-Box, B.C.G. analysis, Boston Box, Boston Matrix, Boston Consulting Group analysis, portfolio diagram... business units and product lines. In broader terms of management, the BCG matrix
input output
input output  java program using fileinputstream and fileoutputstream   Hi Friend, Try the following code: import java.io.*; class FileInputStreamAndFileOutputStream { public static void main(String[] args
input output
input output  java program using fileinputstream and fileoutputstream   Hi Friend, Try the following code: import java.io.*; class FileInputStreamAndFileOutputStream { public static void main(String[] args
input output
/O is used to input any thing by the keyboard or a file. This is done using... Input And Output       Introduction The Java I/O means Java Input/Output and is a part
Java Matrix Multiplication Example
(String[] args){ Scanner input = new Scanner(System.in); System.out.print("...Java Matrix Multiplication Example In this tutorial, you will learn how... and then accept the matrix elements as array elements. We have declared two
Multiplication of two Matrix
to multiply both matrix. The both matrix will be multiplied by using the for loop. So... Multiplication of Two Matrix   ... that teaches you the method to multiply two matrix. We are going to make a simple
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
Multiplication of two Matrix
by using the array1.length. After getting both matrix then multiply to it. Both matrix will be multiplied to each other by using 'for' loop. So the output... for multiplying two matrix to each other. Here providing you Java source code
Summary - Scanner
Java: Summary - Scanner The main use of java.util.Scanner is to read values from System.in or a file. Many Scanner methods fit a simple pattern: nextXYZ..., but Scanner also supports BigDecimal, BigInteger, Float (returns float), Boolean (returns
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
input - Java Beginners
:"); Scanner input=new Scanner(System.in); String name=input.nextLine... me soon.  Hi Friend, There are lot of ways to input data.You can use the methods of BufferedReader class, Scanner class, StreamTokenizer class
Dividing of two Matrix in Java
to divided both matrix. This program using the two for loop. So the output... Dividing of two Matrix in Java   ... matrix. First all to we have to define class "ArrayDivideMatrix". 
Sum of two Matrix
the matrix. The both matrix will be added by using the for loop with array[i][j... Sum of  two Matrix       In this section, we are going to calculate the sum of two matrix
different type input in java
); } }   Java read input through Scanner: import java.util.*; class...) { Scanner input=new Scanner(System.in); System.out.print("Enter integer...different type input in java  hiiiii... get input different different
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 format
Sum of diagonal of Matrix in C
C Sum of diagonal of Matrix In this section, you will learn how to determine the sum of both the diagonal of 3X3 matrix. For this, we have declared an array of integers and using the for loops, we have determined the sum of both
How to Create Create Matrix of any order
Create Matrix of any order Java Program 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 an m-by-n matrix or m × n matrix, while m
Matrix Example in Java
Matrix Example in Java     ... array as its input. As  it is the multidimensional array so, get the length of each array by using the length variable which will helps us to find the length

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.