Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

S.No: 2 Exp.

Name: Java Program to Display the Fibonacci Series Date: 2022-04-12

ID: 20095A0363
    Page No:
           
Aim:
Write a class FibonacciSeries with a main method. The method receives one command line argument.
Write a program to display fibonacci series i.e. 0 1 1 2 3 5 8 13 21.....

For example:

Cmd Args : 80

0 1 1 2 3 5 8 13 21 34 55

Note: Please don't change the package name.


Source Code:

q10896/FibonacciSeries.java

package q10896;
class FibonacciSeries

public static void main(String args[])

int n=Integer.parseInt(args[0]);

    Rajeev Gandhi Memorial College of Engineering and Technology (Autonomous)      2019-2023-MECH-FDH


int a=0,b=1;

System.out.print(a+ " "+b);

int c=a+b;

while(c<=n)

System.out.print(" "+c);

a=b;

b=c;

c=a+b;

Execution Results - All test cases have succeeded!

Test Case - 1

User Output
0 1 1 2 3 5

Test Case - 2

User Output
0 1 1 2 3 5 8 13 21 34 55

Test Case - 3
User Output
User Output
User Output

0 1 1 2 3 5 8
Test Case - 4

Test Case - 5
Test Case - 3

0 1 1 2 3 5 8 13 21 34 55
0 1 1 2 3 5 8 13 21 34 55

ID: 20095A0363
    Page No:
           
    Rajeev Gandhi Memorial College of Engineering and Technology (Autonomous)      2019-2023-MECH-FDH

You might also like