Skip to content

Instantly share code, notes, and snippets.

@eMahtab
Created November 19, 2015 12:25
Show Gist options
  • Save eMahtab/bb3eaff5f710cd970520 to your computer and use it in GitHub Desktop.
Save eMahtab/bb3eaff5f710cd970520 to your computer and use it in GitHub Desktop.
Java program to print fibonacci numbers. In Fibonacci series each number is sum of previous two numbers.
public class Fibonacci{
public static void main(String args[]){
int n1=0;
int n2=1;
int next=0;
System.out.print(n1+" "+n2+" ");
int loop=1;
while(loop<11){
next=n1+n2;
n1=n2;
n2=next;
System.out.print(next+" ");
loop++;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment