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



Home Answers Viewqa Java-Beginners java 2 d array program

Have Programming Question? Ask it here!
 
 
 


saurabh pratap name
java 2 d array program
1 Answer(s)      3 years and 9 months ago
Posted in : Java Beginners


write a program 2-d matrix addition through user's input?

Advertisement
View Answers

October 18, 2010 at 10:34 AM


Hi Friend,

Try the following code:

import java.util.*;
    class MatrixAddition{
        public static void main(String[] args) throws Exception {
          Scanner input=new Scanner(System.in);
    int[][] A = new int[2][2];
    int[][] B = new int[2][2];
    int[][] C = new int[2][2];
    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("Sum of 2 matrices,Matrix C: ");
        for(int i=0;i<2;i++){
    for(int j=0;j<2;j++){
    C[i][j]=A[i][j]+B[i][j];
    System.out.print(C[i][j]+" ");
    }
    System.out.println();
    }
    }
    }

Thanks



Related Tutorials/Questions & Answers:
java 2 d array program
java 2 d array program  write a program 2-d matrix addition through...[][] A = new int[2][2]; int[][] B = new int[2][2]; int[][] C = new int[2][2...]+" "); } } System.out.println(); System.out.println("Sum of 2 matrices,Matrix C
executing java program with 2 classes
executing java program with 2 classes  how to run a program of java containing more than one class....ex of program is given below.... class C...); } }   Executing java program with 2 classes save the file with D.java
Advertisements
java program based on array
java program based on array  write a program to create an array of 10 integers in main.accept values from the user in that array .now again ask the use another nomber and pass the array and the no. entered to function called
array variable in a java program
array variable in a java program  How do i write a program that will prompt the user for a list of 5 prices, that cosist of the sum of all the prices, the average of the prices, and all prices that are higher than the calculated
How to convert java BigDecimal to normal byte array not 2 s complement
How to convert java BigDecimal to normal byte array not 2 s complement  How to convert java BigDecimal to normal byte array not 2 s complement
how to sort the result of this 2 class program in java.....????
how to sort the result of this 2 class program in java.....????  package setget1_method; import java.util.Scanner; public class Main { { { Scanner input = new Scanner(System.in); LBook[] book = new LBook[5]; String
array program
array program  write a java program which will take 10 elements as command line arguments and count how many times 3 occurs in array
Array list java program - Java Interview Questions
Array list java program  Create an employee class with an employee... an employee id is given, display his name & address? Please provide the DETAIL java... we can display his name and address when an employee id is given? i need java
create and use an array variable in a java program
create and use an array variable in a java program  how do i write a program that will prompt the user for a list of 5 prices, once the user has entered all values , your program should compute and display the following: The sum
program in array
program in array  print("code sample");write a program that initializes an array with ten random integers and then prints four lines of output...[]=new int[10]; System.out.println("Array of Random Numbers
program of array
program of array  write a program that initializes an array with ten random integers and then prints four lines of output,containing:every element at an even index,every even element,all elements in reverse order,and only
C Program for Addtion of 2*2 Diagnol Matrix - Development process
C Program for Addtion of 2*2 Diagnol Matrix   Hello Sir, I want C...;i<2;i++) { for(j=0;j<2;j++){ scanf("%d",&a[i][j]); } } printf("\nThe...;i<2;i++){ for(j=0;j<2;j++){ scanf("%d",&b[i][j]); } } printf("\nThe
Java Loop 2 - Java Beginners
Java Loop 2  WAP to print d following patter wid d help of ne loop possible
Write a java program that encrypt and decrypt some string by adding or removing 2 on each character.
Write a java program that encrypt and decrypt some string by adding or removing 2 on each character.  Write a java program that encrypt and decrypt some string by adding or removing 2 on each character. Example 1 : Please Enter
My first struts 2 program
My first struts 2 program  Hi, Please help me for my first struts 2... from one page to another. Details: I am trying my first Struts 2 example program. I want to pass values from first loginpage.jsp to displaypage.jsp. I
Reverse integer array program
with all the elements in reverse order. For example, if the input array is [2, 4, 6, 8] the output array is [8, 6, 4, 2]. Then call your method from the main method...Reverse integer array program  Been tasked with the following
one dimensional array program
one dimensional array program  Design and implement a java program that will read a file containing numbers and compute the following statistics: the rannge( low, high), the average and the median(middle number). Notes
how to make a program on array
how to make a program on array  When you make a program on array that the element will move downward and upward and when you input twice 0 then thats the time that it will not move. pls. give me a formula...tnx
Three Dimensional Array program
Three Dimensional Array program       This is a very simple Java program. In this program we... the multidimensional array we are going to make a matrix. Now in this program use
Need help in constructing a 2 dimensionla array?
Need help in constructing a 2 dimensionla array?  Construct a 2 dimensional array that for each entry in the array, display the index of the first... array. import java.util.*; public class twoDimension{ public static void main
Program to implement array of Objects.
Program to implement array of Objects.  Create a class it has.... Initialize an array of objects. Pass a name from the command line & search for the name in the array of objects , if it is existing print the information
Java array
Java array  Java program to find first two maximum numbers in an array,using single loop without sorting array
Two Dimensional Array Program
;    This is very simple program of Java. In this lesson we will learn how to display arrange form of two dimensional array program... a integer for array declaration Two dimensional array program. We are going
Two Dimensional array program
to elements of the array such that the last element become the first one and the first become the last.let the program output elements of the first array...Two Dimensional array program  consider a two dimensional array
After changing url params d req checkboxes are not showing as clicked in jsf programming - Java Server Faces Questions
After changing url params d req checkboxes are not showing as clicked in jsf... a treenode. just look at d url : "http://localhost:8080/richfaces-demo-3.2.1.GA... passing album Ids and clientId in url browser and receiving in d Library.java.
Array in Java
. Different types of array used in Java are One-dimensional, Two-dimensional and multi... an array in a program: Declaration of an Array Construction of an Array Initialization of an Array Arrays in Java for different data
program to implement array of objects
program to implement array of objects  import java.io.*; import java.util.*; public class dataa { DataInputStream in=new DataInputStream(System.in); int i; int a[i]=int acid[5]; String name1[i]=new String[5
Two Dimensional Array Program
Two Dimensional Array Program Using Nested for loop       This is a simple Java array  program . In this session we will teach how to use of a two dimensional array
Java Array
Java Array   a) Write an array program that perform the following: i) Declares a String array initialized with the following strings: â?...??. ii) Write a loop that displays the contents of each element in the array
java program
java program   A B C D E F F E D C B A A B C D E E D C B A A B C D D C B A A B C C B A A B B A A A java program to display above triangle
java array
java array  q4.array Write a program that accepts two arrays, an array of fruit names and an array of price of fruits, and a fruit name and returns the price of the fruit. (Assume that a price in the second array corresponds
Changing the value of Array in Java
array program is provided Java application program about the explanation... Changing the Value of Array in Java       This is very simple of one dimensional array program
Java array
Java array   How can one prove that the array is not null but empty
java array
java array  write a java method that takes an array of float values...)){ System.out.println("There are duplicate elements."); Float array...++){ array[i]=new Float(arr[i]); } Set<Float>
Java 2 micro editionJ
Java 2 micro editionJ  Hello, i am using JCreator, for writing my J2ME program, after building the program, it keeps on given me the following errors: package javax.microedition.midlet does not exist package
Moire Pattern 2 Java
Moire Pattern 2 Java   textWhat you are seeing in the screenshot... and height are the same. Make the program from this older code: import...; g2.setColor(Color.black);g2.fillOval(centerX, centerY - ovalWidth / 2, 300, ovalWidth
Program to read 2 integers using oops concepts
Program to read 2 integers using oops concepts  Write a program to read two integers with the following significance. ? The first integer value represents a time of day on a 24 hour clock, so that 1245 represents quarter
java program
java program  write a java program to display array list and calculate the average of given array
java program
java program  write a java program to display array list and calculate the average of given array
arrays part 2 - Java Beginners
arrays part 2  Question 2: Useful Array Algorithms and Operations (5 marks) Upgrade the program in Question 1 so that the program includes.... ? The program searches the value in the integer array by using the above method
java code 1 of 2
java code 1 of 2  Create a washing machine class with methods as switchOn, acceptClothes, acceptDetergent, switchOff. acceptClothes accepts the noofClothes as argument & returns the noofClothes   Hi Friend, Visit
Two Dimensional Array Program Using Nested For Loop
Two Dimensional Array Program Using Nested For Loop        This is very simple program... dimensional array program. Firstly, we have to define class "TwoDimensional "
java array
java array Two cells is a matrix will be called connected if they are adjacent... takes 2 dimensional integer array as input and prints out heaviest island... of all integers in that island. 1 0 0 0 1 0 1 2 2
java code 1 of 2
java code 1 of 2  Create a washing machine class with methods as switchOn, acceptClothes, acceptDetergent, switchOff. acceptClothes accepts the noofClothes as argument & returns the noofClothes   Hi Friend, Try
GUI 2 - Java Beginners
GUI 2  How can I modify this code? Please give me a GUI... world and like it alot. I was wondering where can I go to learn more about java and C++.  Hi You need not worry of where to go and learn about java
task 2 - Java Beginners
task 2  Write a time server that follows the time protocol outlined in RFC 868. When a client connects, the server sends a 4-byte, big-endian, unsigned integer specifying the number of seconds that have passed since 12:00 A.M.
que 2 - Java Beginners
que 2  WAP to input a string & print out the text withthe uppercase & lowercase letters reversed,but all other characters should remain the same. eg: input:WelComE TO School output:wELcOMe to sCHOOL  Hi Friend
java program
java program  write a java program to create an array of size 10 by taking input from bufferreader and find out the average of array elements from that array
java program
java program  write a java program to create an array of size 10 by taking input from bufferreader and find out the average of array elements from that array
java program
java program  write a java program to create an array of size 10 by taking input from bufferreader and find out the average of array elements from that array
Advertisements
 

 

 

DMCA.com