好的,所以这个程序......我不知道如何制作它,更不用说让它工作了。该程序的目标是接受用户 INT 值放入二维数组(5 行 4 列),输出数组,并给出每行的平均值。任何有关使其工作和缩短它的帮助将不胜感激。
import java.io.*;
class largeArray
{
public static void main(String[] args) throws IOException
{
InputStreamReader inStream = new InputStreamReader (System.in);
BufferedReader userInput = new BufferedReader (inStream);
System.out.println("Welcome to the array making program.");
System.out.println("Please enter the first 4 numbers:");
int[][] datArray = new int[5][4];
datArray[0][0] = Integer.parseInt(userInput.readLine());
datArray[0][1] = Integer.parseInt(userInput.readLine());
datArray[0][2] = Integer.parseInt(userInput.readLine());
datArray[0][3] = Integer.parseInt(userInput.readLine());
System.out.println("Please enter in the next 4 numbers:");
datArray[1][0] = Integer.parseInt(userInput.readLine());
datArray[1][1] = Integer.parseInt(userInput.readLine());
datArray[1][2] = Integer.parseInt(userInput.readLine());
datArray[1][3] = Integer.parseInt(userInput.readLine());
System.out.println("Please enter in the third set of 4 numbers:");
datArray[2][0] = Integer.parseInt(userInput.readLine());
datArray[2][1] = Integer.parseInt(userInput.readLine());
datArray[2][2] = Integer.parseInt(userInput.readLine());
datArray[2][3] = Integer.parseInt(userInput.readLine());
System.out.println("Please enter in the fourth set of numbers:");
datArray[3][0] = Integer.parseInt(userInput.readLine());
datArray[3][1] = Integer.parseInt(userInput.readLine());
datArray[3][2] = Integer.parseInt(userInput.readLine());
datArray[3][3] = Integer.parseInt(userInput.readLine());
System.out.println("Please enter in the last set of numbers:");
datArray[4][0] = Integer.parseInt(userInput.readLine());
datArray[4][1] = Integer.parseInt(userInput.readLine());
datArray[4][2] = Integer.parseInt(userInput.readLine());
datArray[4][3] = Integer.parseInt(userInput.readLine());
for(int row = 0; row < datArray.length; row++)
{ System.out.print("Row " + row + ": ");
for (int column = 0; column < datArray[row].length; column++)
System.out.print(datArray[row][column] + " ");
System.out.println( );
}
}
}
当前问题:如何让行中的所有值以简写方式平均?IT 还需要输出平均值。