Print Fibonacci Sequence Java
PROGRAM TO PRINT FIBONACCI SEQUENCE
public class{
public static void Main(String args[]){
int i = 1, n = 10, t1 = 0, t2 = 1;
System.out.print("First " + n + " terms: ");
while (i <= n)
{
System.out.print(t1 + " + ");
int sum = t1 + t2;
t1 = t2;
t2 = sum;
i++;
}
}
}
OUTPUT
0 + 1 + 1 + 2 + 3 + 5 + 8 + 13 + 21 + 34 +
Comments
Post a Comment