// Java Program to find all the subsets of the given Subset
import java.io.*;
import java.util.*;
class Main
{
public static void main(String args[])
{
Scanner obj = new Scanner(System.in);
System.out.print("Enter the no.of elements in the set : ");
int n = obj.nextInt();
int arr[] = new int[n];
for(int i = 0; i < arr.length; i++)
{
System.out.print(" The Set Element " +i+" is : ");
arr[i] = obj.nextInt();
}
int lim = (int)Math.pow(2,arr.length);
for(int i = 0; i < lim; i++)
{
String subset = " ";
int temp = i;
for ( int j = arr.length-1; j>=0; j--)
{
int x = temp % 2;
temp = temp/2;
if (x==0)
{
subset = "" + subset;
}
else
{
subset = arr[j] + " " + subset;
}
}
System.out.println(" The subsets of the Given Set are : { " +subset+"} ");
}
}
}
// Java Program to find all the subsets of the given Subset
import java.io.*;
import java.util.*;
class Subsets
{
public static void main(String args[])
{
Scanner obj = new Scanner(System.in);
System.out.print("Enter the no.of elements in the set : ");
int n = obj.nextInt();
int arr[] = new int[n];
for(int i = 0; i < arr.length; i++)
{
System.out.print(" The Set Element " +i+" is : ");
arr[i] = obj.nextInt();
}
int lim = (int)Math.pow(2,arr.length);
for(int i = 0; i < lim; i++)
{
String subset = " ";
int temp = i;
for ( int j = arr.length-1; j>=0; j--)
{
int x = temp % 2;
temp = temp/2;
if (x==0)
{
subset = "" + subset;
}
else
{
subset = arr[j] + " " + subset;
}
}
System.out.println(" The subsets of the Given Set are : { " +subset+"} ");
}
}
}