Count ways to obtain given sum by repeated throws of a dice | Java program for the above approach ; Function to find the number of ways to get the sum N with throw of dice ; Base Case ; Stores the count of total number of ways to get sum N ; Recur for all 6 states ; Return answer ; Driver Code ; Function call
import java . util . * ; class GFG { static int findWays ( int N ) { if ( N == 0 ) { return 1 ; } int cnt = 0 ; for ( int i = 1 ; i <= 6 ; i ++ ) { if ( N - i >= 0 ) { cnt = cnt + findWays ( N - i ) ; } } return cnt ; } public static void main ( String [ ] args ) { int N = 4 ; System . out . print ( findWays ( N ) ) ; } }