program to print fibonacci series upto 10 terms in java
Answers
Answered by
4
import java.util.Scanner;
public class Fibonacci
{
public static void main(String[] args)
{
int n, a = 0, b = 0, c = 1;
Scanner s = new Scanner(System.in);
System.out.print("Enter value of n:");
n = s.nextInt();
System.out.print("Fibonacci Series:");
for(int i = 1; i <= n; i++)
{
a = b;
b = c;
c = a + b;
System.out.print(a+" ");
}
}
}
rishabhraushan200524:
a program for beginners please
Answered by
9
Java is a machine independent language which can work on any platform. Its an object oriented programming which stress on object rather than data.
The main parts while doing Java programming are package, Class ,input variables, condition updating.
◼Fibocci is a series in which the sum of each term is the sum of prevoius two numbers.
The following programming is done by io package of Java.
import Java. io. *;
class check
{
public static void main(String args[])throws Exception
{
int t ,a = 1 ,b=1 ,c;
System.out.print( a+", "+b+", ");
for(i = 1 ; i <=10 ;i ++)
{
c=a + b ;
System.out.print( c+", ");
a=b;
b=c;
}
}
}
1 , 1 , 2 , 3 , 5 , 8 , 13 , 21 , 34 , 55,
Similar questions