Count of ways to rearrange N digits and M alphabets keeping all alphabets together | Java program for the above approach ; Function to find the factorial of the given number ; Function to count ways to rearrange characters of the String such that all alphabets are adjacent . ; Stores factorial of ( N + 1 ) ; Stores factorial of ; Driver Code ; Given a and b ; Function call
import java . util . * ; class GFG { static int fact ( int n ) { int ans = 1 ; for ( int i = 2 ; i <= n ; i ++ ) ans = ans * i ; return ans ; } static int findComb ( int N , int M ) { int x = fact ( N + 1 ) ; int y = fact ( M ) ; return ( x * y ) ; } public static void main ( String [ ] args ) { int N = 2 ; int M = 2 ; System . out . print ( findComb ( N , M ) ) ; } }