java

amrutha
java
1 Answer(s)      6 years and 7 months ago
Posted in : Java Beginners

How to find the sum of individual rows and columns of a matrix in java??

March 8, 2011 at 5:13 PM

Java find the sum of individual rows and columns of a matrix

```import java.util.*;
class FindSumMatrix{

public static void main(String[] args){
Scanner input = new Scanner(System.in);
int[][] A = 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();
}
}
int c1=0,c2=0,c3=0,r1=0,r2=0,r3=0;
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]+" ");
}
}
for (int i=0 ; i < A.length ; i++){
c1+=A[i][0];
c2+=A[i][1];
c3+=A[i][2];
}

for (int i=0 ; i < A.length ; i++){
r1+=A[0][i];
r2+=A[1][i];
r3+=A[2][i];
}
System.out.println();
System.out.println();
System.out.println("Col1: "+c1);
System.out.println("Col2: "+c2);
System.out.println("Col3: "+c3);

System.out.println("Row1: "+r1);
System.out.println("Row2: "+r2);
System.out.println("Row3: "+r3);
}
}
```

Related Tutorials/Questions & Answers:
java
java  diff bt core java and java
java
java  what is java
JAVA
JAVA  how the name came for java language as "JAVA
java
java   why iterator in java if we for loop
java
java  explain technologies are used in java now days and structure java
java
java  different between java & core java
Java
Java   Whether Java is pure object oriented Language
java
java  is java open source
java
java  what is java reflection
java
java   in java does not pointers concept but what is nullpointers in java?   nullpointer is a runtime Exception
java
what is the size of array in java ?  what is the size of array in java ? what is the mean of finalize in java
java
java   What is ?static? keyword
java
java  RARP implementation using java socket
java
java  sample code for RARP using java
java
java  Does java allows multiline comments
Java
Java  how to do java in command prompt
java
java  give a simple example for inheritance in java
java
java  give a simple example for inheritance in java
java
java  why to set classpath in java
java
java  why to set classpath in java
java
java  why to set classpath in java
java
java  why to set classpath in java
java
java  Write a java code to print "ABABBABCABABBA
java
java  write a program in java to acess the email
java
java  send me java interview questions
java
java  how use java method
java
java  what are JAVA applications development tools
Java
Java   Whether Java is Programming Language or it is SOftware
java
java  is java purely object oriented language
java
java  why multiple inheritance is not possible in java
java
java  explain object oriented concept in java