Sorting even numbers from a file

  • 16
If one ordered isomorph isn't sure if another ordered isomorph is sober, he asks him to pass a simple test: read a file name from the console, read a set of numbers from the file, sort only the even numbers in ascending order, and then display them on the screen. Can you pass?
You can't complete this task, because you're not signed in.
Comments (6)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
yehuda b Level 23, Beersheba, Israel
21 May 2020, 18:30
Interesting, when I used Scanner to read the file, (after getting the filename, and creating a FileInputStream with the filename passed as an argument) even though the code was doing exactly the same thing as when I used BufferedReader in the end, it didn't validate because of too many lines. I used Scanner because the logic was simple: while Scanner hasNext, add nextInt to a list etc. which you can't do with BufferedReader.
Switch/Cypher Level 25, Bexleyheath, United Kingdom
10 October 2020, 21:09
Buffered Reader had too many lines because it read the numbers as ASCII code, not as the numbers they are.
MBC Level 14, Apeldoorn, Netherlands
6 February 2020, 14:48
I have tested it myself and it works, but the tests claim that it doesn't print anything. even though it does do it in ascending order
MBC Level 14, Apeldoorn, Netherlands
5 February 2020, 15:09
Does anyone know what the issue with my
even.add(Integer.parseInt(n));
might be?
Oleh Level 32, Kyiv, Ukraine
28 February 2019, 12:36
Lost bunch of time before my first try to verify task on fixing bug. But to the surprise verifier doesn't even check this scenario. The problem was that last line of file didn't read. My algorithm was next: 1. Read file by bytes; 2. Save byte to the buffer if it doesn't equal 10 (ASCII's end of line) ; 3. If byte equals 10 then convert buffer to the string (and then to the int) 4. Add converted buffer to the arraylist. 5. erase buffer So as you can see, if there is no empty line in the end then last number doesn't add to the arraylist either. How can i check end of file, if i am using InputStream.read()? P.S. Should i create this question in the help section even i already completed the task?
Ivan Level 22, Nope, Bulgaria
3 December 2019, 08:09
You can do so, it is always helpful to have guidance on tasks!