Reading integers from a file in Java -


i'm trying read integers file in java , display highest value, i'm having difficult time thinking it.

import java.util.scanner; import java.util.*; import java.io.*;  public class myfile {     public static void main(string[] args) throws exception     {         string filename;         scanner in = new scanner(system.in);          system.out.println("enter name of file.");          filename = in.nextline();         file file = new file("myfile.txt");         scanner inputfile = new scanner(file);         while(inputfile.hasnext())         {             int compare = inputfile.nextint();         }     } } 

the file called myfile.txt , has integers 23, 34, 45, , 2.

if require find highest value file, can do:

int max = integer.min_value; while(inputfile.hasnext()) {      int compare = inputfile.nextint();      if (compare > max){          max = compare;      } } system.out.println("highest value:"+ max); 

is looking for?


Comments

Popular posts from this blog

javascript - Confirm a form & display message if form is valid with JQuery -

Retrieving ETA (estimated time of arrival) with Google Distance Matrix API and public transit as transport mode -

ionic framework - Meteor - Error: Failed to execute 'insertBefore' on 'Node' -