write a java program that print the fibonacci series for a give number


write a java program that print the fibonacci series for a give number
Week 2
a) Aim: To Write a java program that print the fibonacci series for a             give number.
Source Code:
import java.io.*;
class Fibonacci {
public static void main(String[] args) throws IOException
{
DataInputStream in=new DataInputStream(System.in);
String s;
int a=1,b=1,c=a+b;
int n;
System.out.print(“Enter nth value? “);
s=in.readLine();
n=Integer.parseInt(s);
System.out.print(a+”,”+b);
while(c<=n)
 {
 System.out.print(c+”,”);
 a=b;
 b=c;
c=a+b;
 }
 }
 }
Compilation & Execution: D:/cse>javac fibonacci.java
D:/cse>java fibanocci
 
OutPut
Enter nth value? 21

1,1,2,3,5,8,13,21

write a java program that print the fibonacci series for a give number

Have any Question or Comment?

5 comments on “write a java program that print the fibonacci series for a give number

[…] write a java program that print the fibonacci series for a give number. […]

[…] list of names in ascending order Write a java program to perform multiplication of two matrices write a java program that print the fibonacci series for a give number. Write a Java Program that find the factorial of a number Write a Java program that prints all real […]

[…] list of names in ascending order Write a java program to perform multiplication of two matrices write a java program that print the fibonacci series for a give number. Write a Java Program that find the factorial of a number Write a Java program that prints all […]

[…] write a java program that print the fibonacci series for a give number. […]

[…] write a java program that print the fibonacci series for a give number. […]

Leave a Reply

Your email address will not be published. Required fields are marked *

Categories

You have successfully subscribed to myprogrammingschool

There was an error while trying to send your request. Please try again.

My Programming School will use the information you provide on this form to be in touch with you and to provide updates and marketing.