Skip to content

Instantly share code, notes, and snippets.

@sayham-sjb
Last active January 25, 2018 18:15
Show Gist options
  • Save sayham-sjb/9329fb67a569b9f8550b5a7990f81e4c to your computer and use it in GitHub Desktop.
Save sayham-sjb/9329fb67a569b9f8550b5a7990f81e4c to your computer and use it in GitHub Desktop.
fibonacci #java #VS
Private static int index = 0;
public static void main (String[] args){
int n1 = 0;
int n2 = 1;
System.out.println(“index: “ + index + “ = “ + n1);
fibonacci(n1, n2);
}
public static void fibonacci(int n1, int n2){
System.out.println(“index: “ + index + “ = “ + n2);
if (index == 20){ //Stopping point.
return;
}
index++; //Make sure to increment our index to walk towards the end.
fibonacci(n2, n1 + n2);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment