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(5)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
yehuda bLevel 17 , Beersheba
21 May, 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.
MBCLevel 14 , Apeldoorn
6 February, 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
MBCLevel 14 , Apeldoorn
5 February, 15:09
Does anyone know what the issue with my
even.add(Integer.parseInt(n));
might be?
OlehLevel 32 , Kyiv
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?
IvanLevel 22 , Nope
3 December 2019, 08:09
You can do so, it is always helpful to have guidance on tasks!