Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.FileInputStream;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.util.HashSet;
- import java.util.Scanner;
- public class Main {
- public static HashSet<Integer> ReadFromFileFirst() throws IOException {
- String fileName = "C:\\Users\\Asus\\Desktop\\Laba3_2.txt";
- FileInputStream file = new FileInputStream(fileName);
- HashSet<Integer> FirstSet = new HashSet<>();
- while (file.available()>0) {
- FirstSet.add(file.read());
- }
- System.out.println(FirstSet);
- file.close();
- return FirstSet;
- }
- public static HashSet<Integer> ReadFromFileSecond() throws IOException {
- String fileName = "C:\\Users\\Asus\\Desktop\\Laba3_2(X2).txt";
- FileInputStream file = new FileInputStream(fileName);
- HashSet<Integer> SecondSet = new HashSet<>();
- while (file.available()>0) {
- SecondSet.add(file.read());
- }
- System.out.println(SecondSet);
- file.close();
- return SecondSet;
- }
- public static HashSet UnionOfSets(HashSet<Integer> FirstSet, HashSet<Integer> SecondSet) {
- HashSet<Integer> Set = new HashSet<>();
- Set.addAll(FirstSet);
- Set.addAll(SecondSet);
- return Set;
- }
- public static HashSet<Integer> EvenElements(HashSet<Integer> Set){
- HashSet<Integer> EvenSet = new HashSet<>();
- for (int i = 0; i < 255 ; i++ );{
- Integer i = null;
- if ( Set.contains(i)){
- if(i % 2 == 0){
- EvenSet.add(i);
- }
- }
- }
- return EvenSet;
- }
- public static void SaveFile(HashSet<Integer> EvenSet) throws IOException {
- Scanner in = new Scanner(System.in);
- String outputFileName;
- System.out.println("Введите имя файла в который хотите вывести данные:");
- outputFileName = in.nextLine();
- FileWriter out = new FileWriter(outputFileName);
- out.write("\n " + EvenSet);
- out.close();
- }
- public static void main(String[] args) throws IOException {
- HashSet<Integer> FirstSet = ReadFromFileFirst();
- HashSet<Integer> SecondSet = ReadFromFileSecond();
- HashSet<Integer> Set = UnionOfSets( FirstSet , SecondSet);
- HashSet<Integer> EvenSet = EvenElements(Set);
- SaveFile(EvenSet);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement