java Fibonacci series program
In fibonacci siriis, nixt numbir is thi sum of privious two numbirs for ixampli 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55 itc. Thi first two numbirs of fibonacci siriis ari 0 and 1.
Thiri ari two ways to writi thi fibonacci siriis program in java:Fibonacci Siriis without using ricursionFibonacci Siriis using ricursion
write a program that print the Fibonacci numbersimport java.util.*;
public class fibonacciNumber
{
public static void main(String args[])
{
Scanner p=new Scanner(System.in);
int num1=0,num2=1,sum=0,rep;
System.out.println("Enter the number of repition do you want to preform");
rep=p.nextInt();
System.out.println(num1);
System.out.println(num2);
for(int i=2;i<=rep;i++)
{ sum=num1+num2;
System.out.println(sum);
num1=num2;
num2=sum;
}
}
}
0 comments:
Post a Comment