Wednesday 23 July 2014

Show first 10 Fibonacci numbers in message dialog box with java code.

import javax.swing.*;
class Fibo
{
                public static void main(String[] args){
                int n1 = 0,n2 = 1,n3;
                String st;
                st = n1 + "\n" + n2 + "\n";
                for(int i = 1; i<10; i++){
                                n3 = n1 + n2;
                                st += ( n3 + "\n");
                                n1 = n2;
                                n2 = n3;
                }
                JOptionPane.showMessageDialog(null, st);
                System.exit(0);
                }                             

}

No comments:

Post a Comment