methods - Summing digits of integers in an input file java error -


I am trying to read the integer from an input file "input.txt" and to separate the integer and add points . This code is telling me that the method for the amount is an illegal start. Any sign?

  public static zero main (string [] args) {// declaration boolean file open = true; Scanner inputfile = null; Int sum, number; // read the input string filename = ""; System.out.println ("Input file name to be opened"); Scanner input = new scanner (System.in); fileName = input.nextLine (); {InputFile = new scanner (try new file (filename)); } Hold (FileNotFoundException e) {System.out.println ("--- file not found! ---"); File = false; } If (fileOpened & Input File. HasNext ()) {sumNum = sum (num); // When calling method (inputFile.hasNextInt ()) {if (inputFile.hasNextInt ()) {num = inputFile.nextInt (); System.out.println ("Number of + num +" is the sum of points: "+ sumnum); } And {inputFile.next (); }}} Public fixed int amount (integer number) {int i, sumNum = 0; For (i = 1; i    

The way you are missing } in your main . You have not started your num .

I have fixed the main to give the right output. There were other problems in your system: You were calling the sum method in the wrong place, try the following answer:

  public static zero main (string [] args ) {// announcements Boolean file opened = true; Scanner inputfile = null; Int yoga, number = 0; // read the input string filename = ""; System.out.println ("Input file name to be opened"); Scanner input = new scanner (System.in); fileName = input.nextLine (); {InputFile = new scanner (try new file (filename)); } Hold (FileNotFoundException e) {System.out.println ("--- file not found! ---"); File = false; } While (inputFile.hasNextInt ()) {num = inputFile.nextInt (); SumNum = sum (num); // method call system.out.println ("Number of + num +" is the sum of points: "+ sumnum); }}    

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -