Advertisement
Guest User

Untitled

a guest
Sep 26th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. package com.javarush.test.level13.lesson11.bonus01;
  2.  
  3. /* Сортировка четных чисел из файла
  4. 1. Ввести имя файла с консоли.
  5. 2. Прочитать из него набор чисел.
  6. 3. Вывести на консоль только четные, отсортированные по возрастанию.
  7. Пример ввода:
  8. 5
  9. 8
  10. 11
  11. 3
  12. 2
  13. 10
  14. Пример вывода:
  15. 2
  16. 8
  17. 10
  18. */
  19.  
  20. import java.io.BufferedReader;
  21. import java.io.FileInputStream;
  22. import java.io.IOException;
  23. import java.io.InputStreamReader;
  24. import java.util.ArrayList;
  25. import java.util.TreeSet;
  26.  
  27. public class Solution
  28. {
  29. public static void main(String[] args) throws IOException
  30. {
  31. BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
  32. String name = bf.readLine();
  33. FileInputStream in = new FileInputStream(name);
  34. ArrayList<Integer> num = new ArrayList<>();
  35. while(in.available()>0){
  36. int data = in.read();
  37. num.add(data);
  38. }
  39.  
  40.  
  41.  
  42. TreeSet<Integer> tre = new TreeSet<>();
  43. for(int i=0;i<num.size();i++){
  44. tre.add(num.get(i));
  45. }
  46. for(int s :tre) System.out.println(s);
  47.  
  48. // напишите тут ваш код
  49. }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement