Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.16 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.Scanner;
  3. import java.util.regex.Pattern;
  4. public class Array{
  5.  
  6.     public static void main(String args[]){
  7.  
  8.         Scanner in = new Scanner(System.in);
  9.  
  10.         System.out.print("Enter Set: ");
  11.         String inputSet = in.nextLine();
  12.  
  13.         System.out.print("\nEnter Subset: ");
  14.         String subSet = in.nextLine();
  15.        
  16.         System.out.println();
  17.        
  18.         int setA[] = stringToInt(inputSet);
  19.         int setB[] = stringToInt(subSet);
  20.  
  21.         System.out.print("set { ");
  22.  
  23.         for(int x : setA){
  24.             for(int y : setB)
  25.                 if(x == y+1)
  26.                     System.out.print(x+ " ");
  27.            
  28.         }
  29.  
  30.         System.out.print("} is subset of set { " +inputSet +" }");
  31.     }
  32.  
  33.     public static int[] stringToInt(String items){
  34.         Pattern pattern = null;
  35.         pattern = pattern.compile(",");
  36.         String item[] = pattern.split(items);
  37.  
  38.         int set[] = new int[item.length];
  39.  
  40.         int count = 0;
  41.         for(String s : item) {
  42.             set[count] = Integer.parseInt(s);
  43.             count++;
  44.         }
  45.  
  46.         return set;
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement