Computer Applications
Write a program to print the Fibonacci series upto 10 terms.
[A series of numbers in which each number is the sum of the two preceding numbers.
For example: 0,1,1,2,3, …………… n].
Java
Java Iterative Stmts
70 Likes
Answer
public class KboatFibonacci
{
public static void main(String args[]) {
int a = 0;
int b = 1;
System.out.print(a + " " + b);
/*
* i is starting from 3 below
* instead of 1 because we have
* already printed 2 terms of
* the series. The for loop will
* print the series from third
* term onwards.
*/
for (int i = 3; i <= 10; i++) {
int term = a + b;
System.out.print(" " + term);
a = b;
b = term;
}
}
}
Output
Answered By
29 Likes
Related Questions
Write a program to print all the prime numbers between 1 and 100.
Create a program to display whether the entered character is in uppercase or lowercase.
Write a program to print the largest of three numbers.
Write a Java program using the switch case to print the corresponding days of numbers.
For example: 1= Monday…. 7 = Sunday