My computer science teacher told my class to write a code where a frog jumps a staircase to eat a fly. The frog can only jump 3 stairs at once and the frog must jump any number of stairs input. The program must compute the number of possible ways the frog can get to the top of the staircase and also spit out the paths it can take. s= # of stairs
V My code so far has errors in the jumpsPossible method and I really don't understand why can anyone help?
class frog { static int totalPaths=0; public static void jumpsPossible(int i, int s, String path){ if (i==s){ totalPaths++; System.out.println (path); } if (i<s){ jumpsPossible(i+1,s,path+1); jumpsPossible(i+2,s,path+2); jumpsPossible(i+3,s,path+3); } } public static void main (String [] args) { Integer s = Integer.valueOf(args [0]); System.out.println ("Freddie the Frog will now jump" + s + " stairs to catch a fly!"); jumpsPossible(0,s,""); System.out.println ("Freddie can get to the top of the staircase in " + jumpsPossible + " ways."); } }