Java Fibonacci Series Program
Source Codeimport java.lang.*; import java.util.*; class fibonacci { public static void main(String arg[]) { int a=0,b=1,c=0,i,num; Scanner scan = new Scanner(System.in); System.out.print("enter any number for fibonacci series: "); num = scan.nextInt(); System.out.println("Fibonacci Series is:"); for(i=0;i<num;i++) { System.out.print(c+"\t"); a=b; b=c; c=a+b; } } }
Output
In this java program create a class Fibonacci and use concept of Scanner class to accept a number from user. This program generate Fibonacci series for input.
No comments:
Post a Comment
Dont SPAM