Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.21 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("Enter 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)
  26.                     System.out.print(x);
  27.                 if(x == y+1)
  28.                     System.out.print(",");
  29.             }
  30.         }
  31.  
  32.         System.out.print(" } is subset of set { " +inputSet +" }");
  33.     }
  34.  
  35.     public static int[] stringToInt(String items){
  36.         Pattern pattern = null;
  37.         pattern = pattern.compile(",");
  38.         String item[] = pattern.split(items);
  39.  
  40.         int set[] = new int[item.length];
  41.  
  42.         int count = 0;
  43.         for(String s : item) {
  44.             set[count] = Integer.parseInt(s);
  45.             count++;
  46.         }
  47.  
  48.         return set;
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement