rowsTotal = new double[rows];
  positions = new double [rows][];

  for(index = 0; index < rows; index++){
      System.out.print("Please enter number of positions in row " + (char)(index+65) + " : ");
      pos = keyboard.nextInt();
      if(pos > MAX_POSITIONS){
          System.out.print("ERROR: Out of range, try again: ");
          pos = keyboard.nextInt();
      }
      positions[index] = new double[pos];


      }


  System.out.print("(A)dd, (R)emove, (P)rint,          e(X)it : ");
  input = keyboard.next().charAt(0);
  input = Character.toUpperCase(input);


  if(input == 'P'){
      for(int index1= 0; index1 < rows; index1++){
          for(int pos1= 0; pos1 < pos; pos1++){

              System.out.print(positions[index1][pos1] + " ");
          }



  }

  }


我希望输出将其显示为每一行的矩阵,因此对于第一行,它将是A行的值,第二行将是B行的值,依此类推

但是将其全部输出在同一行中,例如:

0.0 0.0 0.0 0.0

而不是

0.0 0.0(A行)

0.0 0.0(行B)

最佳答案

您在每一行之后都忘记了换行符。

for(int index1 = 0; index1 < rows; index1++)
{
    for(int pos1 = 0; pos1 < pos; pos1++)
    {
        System.out.print(positions[index1][pos1] + " ");
    }
    System.out.println(); // <-- This one!
}

10-07 17:00