Mencari BIlangan Faktorial Dengan JAVA

Bilangan faktorial mempunyai rumus n! = (n-1).(n-2).(n-3).....1
Contoh perhitungan bilangan faktorial 4! = 4.3.2.1 = 24

Berikut adalah script untuk membuat program mencari bilangan faktorial dengan menggunakan java. Saya menggunakan jFrame form untuk membuat aplikasi.

int n = Integer.parseInt(jTextField1.getText());
    double has = 1;
    for (int i = n; i > 0; i--) {
        if (i == 1) {
            jTextArea1.setText(jTextArea1.getText() + i);
        } else {
            jTextArea1.setText(jTextArea1.getText() + i + " x ");
        }
        has = has * i;
    }

    jTextArea1.setText(jTextArea1.getText() + "\n\n" + has);


Berikut adalah tampilan dari aplikasi mencari bilangan faktorial



Share on Google Plus

About Mr.J

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Blogger Comment
    Facebook Comment

0 comments:

Posting Komentar