-5

プログラムを正しくコンパイルできません。1 と 0 のランダムなテーブルを作成しようとしています。配列のサイズはユーザーによって決定され、プログラムは上記のテーブルを分析し、行内の 1 の数をカウントする別のテーブルを出力することになっています。

import java.util.Scanner;

public class Homework {

 public static void scanInfo()
 {

 Scanner input = new Scanner(System.in);

System.out.println("Enter number of rows: ");    
int rows = input.nextInt();

System.out.println("Enter number of columns: "); 
int columns = input.nextInt();

int[][] nums = new int[rows][columns];            

 static int[][] sample = nums;

}
   static int[][] results = new int[4][5];
   static int goodData = 1;

   public static void main(String[] args) {
      analyzeTable();
      printTable(results);
   } 

   static void analyzeTable() {
      int row=0;
      while (row < sample.length) {
         analyzeRow(row);
         row++;
      }
   }

   static void analyzeRow(int row) {
      int xCol = 0;
      int rCount = 0;
      while (xCol < sample[row].length) {
         rCount = analyzeCell(row,xCol);
         results[row][xCol] = rCount; // instead of print
         xCol++;
      }
   }

   static int analyzeCell(int row, int col) {
      int xCol = col;   // varies in the loop
      int runCount = 0;  // initialize counter
      int rowLen = sample[row].length;   // shorthand
      int hereData = sample[row][xCol];  // shorthand
      while (hereData == goodData && xCol < rowLen) {
         runCount++;
         xCol++;
         if (xCol < rowLen) { hereData = sample[row][xCol];} 
      }
      return runCount;
   }

  /*   Start Print Stuff */
  public static void printTable(int[][] aTable ) {
    for (int[] row : aTable) {
      printRow(row);
      System.out.println();
    }
  }
  public static void printRow(int[] aRow) {
    for (int cell  : aRow) {
      System.out.printf("%d ", cell);
    }
  }
}
  /*   End Print Stuff */
4

1 に答える 1