Sample Programs in java

Java Example Program for fibonacci series

[java]
/* java program for Fibnacci series*/
/**
*@author:Candidjava.com
*@Description:Program for find the Fibonacci series of a given number
*/
public class Fibonacci {
public static void main(String[] args) {
int n;
int c = 0;
int a = 0;
int b = 1;
System.out.println("Fibonacci series:");
for (int i = 1; i <= 10; i++) {
a = b;
b = c;
c = a + b;
System.out.println(c); // Display the value of c
}
}
}
[/java]

Output:

1
1
2
3
5
8
13
21
34
55