0% found this document useful (0 votes)
13 views

Q10896/Fibonacciseries - Java: S.No: 2 Date: 2022-04-12

The document describes a Java program to display the Fibonacci series. The program takes a command line argument representing the maximum number. It initializes two variables a and b to 0 and 1. It prints a and b and calculates the next number c as the sum of a and b. It prints c and updates a, b and c in a while loop until c exceeds the maximum number. The program was tested with different maximum numbers and the output matched the expected Fibonacci series in all test cases.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Q10896/Fibonacciseries - Java: S.No: 2 Date: 2022-04-12

The document describes a Java program to display the Fibonacci series. The program takes a command line argument representing the maximum number. It initializes two variables a and b to 0 and 1. It prints a and b and calculates the next number c as the sum of a and b. It prints c and updates a, b and c in a while loop until c exceeds the maximum number. The program was tested with different maximum numbers and the output matched the expected Fibonacci series in all test cases.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 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