FIBONACCI
import javax.swing.*;
public class Fib{
public static void main(String[] args){
Fib fb=new Fib();
}
public Fib(){
String output="",input;
int num,a,b,sum=0;
input= JOptionPane.showInputDialog("Enter a number:");
num=Integer.parseInt(input);
a=0;
b=1;
for(int x=1;x<=num;x++)
{
sum=a+b;
a=b;
b=sum;
output+=sum+" ";
output+="\n";
}
JOptionPane.showMessageDialog(null,output,"Jo!!,THIS IS A FIBONACCI...BABY",JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
}
}
No comments:
Post a Comment