i am practicing my java by counting possible ways to reach n with a dice. and when input n value to smaller number, it works. but when i input n value to 100, it got infinite looping.
can u guys help me ?
here is my code :
public static void main(String[] args)
{
testCode test = new testCode();
System.out.println(test.countWays(100));
}
private static int countWays(int n)
{
if(n<=1)
{
return 1;
}
else
{
System.out.println("counting ....");
return countWays(n-6) + countWays(n-5) + countWays(n-4) + countWays(n-3) + countWays(n-2) + countWays(n-1);
}
}