Html/javascript

Java program to find fibonacci series upto n terms -Education notes for study

 Java program to find fibonacci series upto n terms -Education notes for study 


*display Fibonacci series upto n terms:- 

   

   

->

class fibonacci 

{

Public static void main (String args[])

{

int f1=0, f2=1,f3=n;

n=

 Integer.parseInt(args [0]);

System.out.println("The Fibonacci series upto "+n"terms are:");

for (int i=2; i <n;  i++)

{

f3=f1+f2;

f1=f2;

f2=f3;

System.out.println(f3+"\n");

}

}

}



Output:-

Compile:- javac programname.java

Run :-  java programname

[Note ]

Assign the value at the run time 

*java programname 5

Now run,

It shows the output of fibonacci series upto n terms;



Read my previous blogs  related to java :

1:java Introduction -Characters of Java program:

 https://getnotesforstudy.blogspot.com/2022/07/java-introduction-characters-of-java.html


2:Structure of Java program:

https://getnotesforstudy.blogspot.com/2022/07/structure.html


3:Java Tokens - in Java:

https://getnotesforstudy.blogspot.com/2022/07/java-tokens-education-notes-for-study.html


4:Java Virtual Machine:

https://getnotesforstudy.blogspot.com/2022/07/java-virtual-machine-jvm-education.html

Post a Comment

0 Comments