문제

I am having trouble creating a method to import data from a txt file into a 1d string array and a 2d double array. Here is what I have thus far:

public static void main(String[] args){
    String[] productName = new String[100];
    double[][] sales = new double[100][5];
    initializeArrays(productName, sales);

....}
  public static void initializeArrays(String a[], double b[][]){
    try
    {
      String output = "";
      File inputFile = new File("c:/temp/salesdata.txt");
      if (inputFile.exists())
      {
        Scanner scanner = new Scanner(inputFile);
        while (scanner.hasNext())
        {
          for (i=1;i<6;i++)
          {
            b[a.length][i]=scanner.nextDouble();  
          }
          rowCount += 1;
        }
      }

    }
      catch (FileNotFoundException e)
    {
      System.out.println("Error reading file: ");
    }

올바른 솔루션이 없습니다

다른 팁

Try this code:

public static void initializeArrays(String a[], double b[][]){
    try
    {
      String output = "";
      File inputFile = new File("c:/temp/salesdata.txt");
      int counter = 0;
      if (inputFile.exists())
      {
        Scanner scanner = new Scanner(inputFile);
        while (scanner.hasNext())
        {
          for (i=1;i<6;i++)
          {
            b[counter][i]=scanner.nextDouble();  
          }
          counter++;
          rowCount += 1;
        }
      }

    }
      catch (FileNotFoundException e)
    {
      System.out.println("Error reading file: ");
    }
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top