-1

Whenever I try to run this code I get the error java.util.NoSuchElementException: No line found. I am not sure on what else to do.

public static void getSum(int numberofaccounts)throws FileNotFoundException {
  Scanner keyboard = new Scanner(System.in);

  String filenames = "Money.txt";
  File file = new File(filenames);
  Scanner inputFile = new Scanner(file);
  String[] moneyOfAccount = new String [numberofaccounts];
  int sum = 0;
  int[] MoneyOfAccounts = new int [numberofaccounts];


  for (int i=0;i<numberofaccounts;i++)
  {
     moneyOfAccount[i] = inputFile.nextLine();
     MoneyOfAccounts[i] = Integer.parseInt(moneyOfAccount[i]);
     sum = sum + MoneyOfAccounts[i];
     
  }
  System.out.print("The total amount of money in the bank is: $" + sum + ".");
  return;
}
DevilsHnd
  • 7,644
  • 2
  • 17
  • 21
Ife
  • 1

0 Answers0