aspose file tools*
The moose likes Beginning Java and the fly likes Java Help... so frustrated.... again!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Java Help... so frustrated.... again!!" Watch "Java Help... so frustrated.... again!!" New topic
Author

Java Help... so frustrated.... again!!

Martin vanPutten
Ranch Hand

Joined: Mar 26, 2006
Posts: 124
Here I am again with another problem. This program is suppose to ask for 20 numbers and then it spits out a matrix with 4 rows and 5 columns. Then the program needs to spit out the average of column 1, then 2, then 3, then 4, and 5. My heads already exploded trying to do this... I need help!! javascript: x()
banghead

import java.io.*;

class J18
{
public static void main (String [] args) throws IOException
{
InputStreamReader inStream = new InputStreamReader (System.in);
BufferedReader inData = new BufferedReader (inStream);

int [] [] array = new int [4] [5];
int count;
String inNum;
int row, column;
double mean1;

row = 0;
column = 0;

System.out.println ("Enter 20 numbers.");

for (count = 0; count < 20; count++)
{

inNum = inData.readLine ();
array [row] [column] = Integer.parseInt (inNum);

if (column < 4)
column ++;
else
{
row++;
column = 0;
}
}


for(row = 0; row < array.length; row++)

{
System.out.print("Row " + (row + 1) + ": ");

for (column = 0; column < array[row].length; column++)

System.out.print(array[row][column] + " ");
System.out.println( );
}

{

int row2;

double [][] total = new double[4][5];
do
{ do{

total[row][column] += // This is my problem!!

row2++;
}
while (row2 < 4);

column++;
row2 = 0;

}
while (column < 5);

mean1 = ((total[0][0] + total[1][0] + total[2][0] + total[3][0])/4);

System.out.println ("The average of column number 1 is " + mean1);



}
}}


Live And Let Learn.
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

I suggest getting your other code running first. Working through that should help you with this problem.


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Java Help... so frustrated.... again!!