Computer Science, asked by eileennayak, 1 year ago

write a program to display only 15 fibonacci numbers

Answers

Answered by tiara5
3
public class Fibonacci {

public static void main(String[] args) {

int n = 15, t1 = 0, t2 = 1;
System.out.print("First " + n + " terms: ");

for (int i = 1; i <= n; ++i)
{
System.out.print(t1 + " + ");

int sum = t1 + t2;
t1 = t2;
t2 = sum;
}
}
}
Similar questions