Results 1 to 7 of 7
 12112014, 08:01 PM #1Member
 Join Date
 Oct 2014
 Posts
 20
 Rep Power
 0
why it is not printing the sum of the first row ?
Java Code:public class Lab12 { public static int SumRow(int [][] a){ int row, column, sum=0; for (row=0;row<2;row++ ) { sum=0; for (column=0;column<2;column++) { sum=sum+a[row][column]; } System.out.println("The sum of row "+row+ " is: "+sum); } return sum; } public static int SumCol(int [][] b){ int total=0; for (int column=0;column<2;column++) { total=0; for (int row=0;row<2;row++) { total=total+b[row][column]; } System.out.println("The sum of column "+column+" is: "+total); } return total; } public static int MaxInRow(int[][] c) { int max=0; for (int row=0;row<2;row++) { max=0; for (int column=0; column<2;column++) { if (max<c[row][column]) max=c[row][column]; } System.out.println("The max of row "+row+" is: "+max); } return max; } }
Java Code:public class Lab12main { public static void main (String[] args){ int s,t,m; int [][] a = { { 3,4},{2,1} }; Lab12 ob=new Lab12(); s= ob.SumRow(a); t=ob.SumCol(a); m= ob.MaxInRow(a); } }
The sum of row 1 is: 3
The sum of coloumn 0 is: 5
The sum of coloumn 1 is: 5
The max of row 0 is: 4
The max of row 1 is: 2
it is supposed to print the sum of row o first ?
 12112014, 08:02 PM #2
Re: why it is not printing the sum of the first row ?
What happened when you stepped through this with a debugger? What happened when you added print statements? What happened when you walked through this in your head with a piece of paper and a pencil?
The idea is to figure out where exactly the program's execution differs from your expectations.How to Ask Questions the Smart Way
Static Void Games  GameDev tutorials, free Java and JavaScript hosting!
Static Void Games forum  Come say hello!
 12112014, 08:20 PM #3Member
 Join Date
 Oct 2014
 Posts
 20
 Rep Power
 0
Re: why it is not printing the sum of the first row ?
for row=0 we supposed to get the sum of a[0][0]+a[0][1] which in this case 3+4=7
it supposed to be for row 0 the sum is 7
and then for row 1 the sum is 3 which printed
I don't understand why it is not printing the sum 7
 12112014, 08:26 PM #4
Re: why it is not printing the sum of the first row ?
You might want to use standard naming conventions: variables and method should start with lowercase letters.
When I run your code I get this output:
The sum of row 0 is: 7
The sum of row 1 is: 3
The sum of column 0 is: 5
The sum of column 1 is: 5
The max of row 0 is: 4
The max of row 1 is: 2How to Ask Questions the Smart Way
Static Void Games  GameDev tutorials, free Java and JavaScript hosting!
Static Void Games forum  Come say hello!
 12112014, 08:35 PM #5Member
 Join Date
 Oct 2014
 Posts
 20
 Rep Power
 0
Re: why it is not printing the sum of the first row ?
I just changed the beginning of each method to lower case and still I am getting the same output :(
 12112014, 08:39 PM #6Member
 Join Date
 Oct 2014
 Posts
 20
 Rep Power
 0
Re: why it is not printing the sum of the first row ?
ok thanks I just fixed
 12112014, 08:40 PM #7
Re: why it is not printing the sum of the first row ?
Changing the case of the method names was for our sanity, not for fixing any bugs.
What output are you getting? Is it different than the output I'm getting?
If so, make sure you're running the version you think you are. How are you compiling this? How are you running it?How to Ask Questions the Smart Way
Static Void Games  GameDev tutorials, free Java and JavaScript hosting!
Static Void Games forum  Come say hello!
Similar Threads

Implement Custom Printing Logic & Enhanced Word Documents Printing
By sherazam in forum Java SoftwareReplies: 0Last Post: 12262011, 03:52 PM 
Help with printing an arrayList. printing the first element twice
By kingkongjaffa in forum New To JavaReplies: 9Last Post: 08192011, 12:59 AM 
printing string backwards and printing every other
By droidus in forum New To JavaReplies: 22Last Post: 03102011, 09:17 AM 
Printing
By zzpprk in forum AWT / SwingReplies: 0Last Post: 01202010, 11:25 AM 
Printing Example
By Java Tip in forum SWT TipsReplies: 0Last Post: 07112008, 04:41 PM
Bookmarks