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

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

  1. Pingback: Java program that displays the number of characters,line word

  2. Pingback: Java greater number using loop - My Programming School

  3. Pingback: Java Print function with example | Difference between print () and println () in java

  4. Pingback: To calculate Area of Circle in java program - My Programming School

  5. Pingback: What is a polygon? | Area of Triangle in java - My Programming School

Leave a Comment

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