Question: Write a program called Split in Java that reads a text file, in.txt, that contains a list of positive integers (duplicates are possible, zero is
Write a program called Split in Java that reads a text file, in.txt, that contains a list of positive integers (duplicates are possible, zero is not considered a positive integer) separated by spaces and/or line breaks. After reading the integers, the program prints out Yes if the set of integers can be split into two subsets with equal sums of elements and with equal numbers of elements. Otherwise (if the list if integers cannot be divided into two subsets satisfying the condition above), the program prints out No. Assume that in.txt contains at least 2 integers.
Examples:
If in.txt contains 7 7, the program must print out Yes. In this case, the split is {7) and {7}. Both sets are of size of 1, and have the same sum of elements.
If in.txt contains 5 3 2 4, the program must print out Yes. The split is {2, 5}, {3, 4}. Both sets have the same size, 2, and the same sum, 7.
If in.txt contains 5 7 5 1 1 3, the program must print out Yes. The split is {1, 5, 5} and {1, 3, 7}.Both sets have three elements and the same sum, 11.
If in.txt contains 6 5 8 3 4 4, the program must print out Yes. The split is {4, 5, 6} and {3, 4, 8}. Both sets have the same length, 3, and the same sum, 15.
If in.txt contains 2 6 10 14 4 8 12 16. There are several splits satisfying the requirement: {2, 8, 10, 16} and {4, 6, 12, 14}; {4, 6, 10, 16} and {2, 8, 12, 14}; {4, 8, 10, 14} and {2, 6, 12, 16}; {6, 8, 10, 12} and {2, 4, 14, 16}. Your program does not need to find all of them. It must stop and print Yes after finding the first split satisfying the requirement.
If in.txt contains 2 13 7 5 16 11, the program must print out No. The set of numbers cannot be divided into two subsets with equal sums and the same number of elements.
If in.txt contains 7 8 2 4 5, the program must print out No.
If in.txt contains 8 5 12 24 14 12 4 6, the program must print out No.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
