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

c# - Update a combobox from a presenter (MVP) -

How to understand 2 main() functions after using uftrace to profile the C++ program? -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -