Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.Scanner;
- import java.util.regex.Pattern;
- public class Array{
- public static void main(String args[]){
- Scanner in = new Scanner(System.in);
- System.out.print("Enter Set: ");
- String inputSet = in.nextLine();
- System.out.print("\nEnter Subset: ");
- String subSet = in.nextLine();
- System.out.println();
- int setA[] = stringToInt(inputSet);
- int setB[] = stringToInt(subSet);
- System.out.print("set { ");
- for(int x : setA){
- for(int y : setB)
- if(x == y+1)
- System.out.print(x+ " ");
- }
- System.out.print("} is subset of set { " +inputSet +" }");
- }
- public static int[] stringToInt(String items){
- Pattern pattern = null;
- pattern = pattern.compile(",");
- String item[] = pattern.split(items);
- int set[] = new int[item.length];
- int count = 0;
- for(String s : item) {
- set[count] = Integer.parseInt(s);
- count++;
- }
- return set;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement