0

Is java able to read a file and give out the max value that it contains?

Jwan
  • 51
  • 6
  • Yes, java can read files, and you can do programmy things with the data to find the max value. – matt May 12 '20 at 11:20
  • That should be possible, but solution depends on what you mean by "value". – Pshemo May 12 '20 at 11:20
  • @Pshemo a String followed by a number-value. But the program should only read the number. String is irrelevant. – Jwan May 12 '20 at 11:24
  • Then iterate over such [string][number] tokens, separate [number] part from it, compare to current maximal value and if new number is bigger store it as current max. Repeat until there are no more [string][number] tokens in file. If you have problem with either of those steps please ask about them *specifically*, – Pshemo May 12 '20 at 11:28
  • Where are you at with your java skills? Can you write, compile and run a program? Then you should start breaking your task into chunks, "How do I read a file?" "How do I parse a number from a String?" etc. – matt May 12 '20 at 11:30

1 Answers1

0

I can think of two cases .
Case 1 > You want to read file line by line because of file size or you are running on system with less memory . How can I read a large text file line by line using Java?

Case 2> Read file chunk by chunk Reading file chunk by chunk

Once you get the data in memory , you can use max no logic . e.g

Step 1 > max_no = first no 
step 2> If max_no < input no 
step 3> max_no = input_no
step 4 > continue to read next no till end 

At the end , you will get maximum of input nos in max_no

I hope it helps