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

Martin vanPutten

Ranch Hand

Posts: 124

posted 9 years ago

- 0

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);

}

}}

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.

posted 9 years ago

- 0

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

I agree. Here's the link: http://aspose.com/file-tools |