Skip to content

Instantly share code, notes, and snippets.

@thmain
Created June 5, 2018 04:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thmain/853bbef02653cc83aa18818ef49cd158 to your computer and use it in GitHub Desktop.
Save thmain/853bbef02653cc83aa18818ef49cd158 to your computer and use it in GitHub Desktop.
public class FibonacciSeries {
public static void printFibonacci(int n){
int one = 0;
int two = 1;
System.out.println("First " + n + " elements in fibonacci series are: ");
for (int i = 0; i <n ; i++) {
System.out.print(one + " ");
int temp = one + two;
one = two;
two = temp;
}
}
public static void main(String[] args) {
int n = 10;
printFibonacci(n);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment