Sabtu, 20 April 2013

Contoh codingan perpangkatan recursif dengan menggunakan perulangan DoWhile



import javax.swing.JOptionPane;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Toshiba
 */
public class PangkatDoWhile {
    public static int pangkatInteratif (int x, int y){
        int hasil = 1, i=1;
     
        do{
            hasil = hasil*x;
            i++;
        }while (i<=y);
     
        return hasil;
        }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        String input = JOptionPane.showInputDialog("Massukkan Nilai Pertama");
        int a = Integer.parseInt(input);
     
        String input1 = JOptionPane.showInputDialog("Massukkan Nilai Pangkat");
        int b = Integer.parseInt(input1);
     
     
        System.out.println(" "+a+ " Pangkat " +b+ " = " +pangkatInteratif(a,b));
    }
}


saat di running...

INPUTAN









OUTPUTAN











Kalau kurang jelas, silahkan download filenya disini gan :D

THANKS, semoga bermanfaat :D






0 komentar:

Posting Komentar

 
Copyright © . Selamat Datang Di Blog Bagus Dermawan - Posts · Comments
Theme Template by BTDesigner · Powered by Blogger