Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners 17026-input-using-scanner-and-add Sub Mul input using scanner and add/sub/mul/div of a matrix

Have Programming Question? Ask it here!
 
 
 


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


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


Advertisement
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
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
Advertisements
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
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
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
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
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  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
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, 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
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 addition
matrix addition  hai
matrix addition
matrix addition  hai
matrix substraction
matrix substraction  hai
matrix substraction
matrix substraction  hai
scanner - Java Beginners
scanner   how to ask user to enter index in arry using scanner
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 adddition
matrix adddition   how to write a program matrix addition in java
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
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
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
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
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
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
Matrix Multiplication in Java
the matrix, multiply to it. Both the matrix will multiply to each other by using... by using the println() method. Here is the Example for writing Matrix..., n, p, q, sum = 0, i, j, k; Scanner in = new Scanner(System.in
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
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
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
Magic Matrix in GUI
Magic Matrix in GUI  I want program in java GUI contain magic matrix for numbers
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
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
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
Advertisements
 

 

 

DMCA.com