Tech Master Tutorials
Email Facebook Google LinkedIn Pinterest Twitter
Home Java Java 8 Java Interview Questions Java Programming

Arrays

Finding All Subsets of the Array elements ::

	
	public class AllPossibleSubsets {
	
		public static void main(String[] args) {
			char[] arr={'A','B','C'};
			possibleSubsets(arr, arr.length);
		}
		
		static void possibleSubsets(char A[], int N)
		{
		    for(int i = 0;i < (1 << N); ++i)
		    {
		        for(int j = 0;j < N;++j)
		        {
		            if((i & (1 << j))!=0)
		            {
		            	//Printing the selected elements for the particular subset
		                System.out.print(A[j]+" ");
		            }
		        }
		        System.out.println();
		    }
		}
	
	}