Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.javarush.test.level13.lesson11.bonus01;
- /* Сортировка четных чисел из файла
- 1. Ввести имя файла с консоли.
- 2. Прочитать из него набор чисел.
- 3. Вывести на консоль только четные, отсортированные по возрастанию.
- Пример ввода:
- 5
- 8
- 11
- 3
- 2
- 10
- Пример вывода:
- 2
- 8
- 10
- */
- import java.io.BufferedReader;
- import java.io.FileInputStream;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.util.ArrayList;
- import java.util.TreeSet;
- public class Solution
- {
- public static void main(String[] args) throws IOException
- {
- BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
- String name = bf.readLine();
- FileInputStream in = new FileInputStream(name);
- ArrayList<Integer> num = new ArrayList<>();
- while(in.available()>0){
- int data = in.read();
- num.add(data);
- }
- TreeSet<Integer> tre = new TreeSet<>();
- for(int i=0;i<num.size();i++){
- tre.add(num.get(i));
- }
- for(int s :tre) System.out.println(s);
- // напишите тут ваш код
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement