Count of possible subarrays and subsequences using given length of Array | Java implementation to count the subarray and subsequence of given length of the array ; Function to count the subarray for the given array ; Function to count the subsequence for the given array length ; Driver Code
class GFG { static int countSubarray ( int n ) { return ( ( n ) * ( n + 1 ) ) / 2 ; } static int countSubsequence ( int n ) { return ( int ) Math . pow ( 2 , n ) ; } public static void main ( String [ ] args ) { int n = 5 ; System . out . print ( ( countSubarray ( n ) ) + "NEW_LINE"); System . out . print ( ( countSubsequence ( n ) ) + "NEW_LINE"); } }