java - Program to get the lowest number in a file -
I am trying to access the program to a file name "highscore.txt", then:
< Ol>Write a new number in the file
Get the lowest value in the list of numbers in the file.
I am new to Java, so I do not even know how the file has reached.
I got a code that I believe should be, but when I run the program it says that
is the exception to the thread "main" java.util. InputMismatchException at java.util.Scanner.throwFor (Scanner.java:864) at java.util.Scanner.next (at Java.util.Scanner.nextDouble (scanner.java144185) at game.game.main (game.java: 91 ) Java result: 1
Here is the line 84 - 94, and the code I got.
84: Author wr = new filewriter ("highscore.txt "); 85: Write (attempt); 86: wr.close (); 87: lowest = tries; 88: file file = new file (" high 89: scanner inputfile = new scanner (file); 90: while (inputFile.hasNext ()) {91: numb = inputFile.nextDouble (); 92: if (numerator; minimum) minimum = Number; 93:} 94: input file.close ();
archive < / Code> class. This implements a constant sort ()
method that you want: sorting number a quick and dirty code will look like (assuming you find a number in each row Is):
St Ring line = Reedlain (); Whereas (line! = Null) {numberList.add (integer.party (line)); Line = redline (); } collection. Support (number list);
Now just select the first number from numberList .
Comments
Post a Comment