Fatihul Ulum Community of Knowledge
Would you like to react to this message? Create an account in a few clicks or log in to continue.

while + contoh algoritma sebuah program

Go down

while + contoh algoritma sebuah program Empty while + contoh algoritma sebuah program

Post  arip Fri Oct 30, 2009 6:07 am

Code:
import java.io.*;
 public class BB
 {
    public static void main(String [] args)
    {
       /*
        Class Interest menampilkan investasi
        dari sejumlah uang yang disimpan di-bank
        dengan suku-bunga tertentu selama jangka waktu tertentu
        */
       // deklarasi variable utama
       double principal=0; // identifier untuk modal
       double rate=0; // identifier untuk bunga pertahun
       double interest; // identifier untuk bunga
       int jangka=0; // identifier untuk jangka penyimpanan dalam tahun
       
       // membaca data dari keyboard
       DataInputStream in= new DataInputStream(System.in);
       /* Get the initial investment and interest rate from the user. */
       try {
            System.out.print("Masukan modal awal : ");
            principal = Double.valueOf(in.readLine());
            System.out.print("Masukan suku-bunga : ");
            rate = Double.valueOf(in.readLine());
            rate = rate/100;
            System.out.print("Berapa tahun? ");
            jangka = Integer.parseInt(in.readLine());
          }
          catch (IOException err) {
          }
         
          /* Simulasi investasi untuk beberapa tahun. */
          int years; // Counter tahun yang dilalui
          years =0;
          while (years < jangka)
                {
                 interest = principal * rate;
                 principal = principal + interest; // Add it to principal.
                 years = years + 1; // Count the current year.
                 System.out.print("Nilai investment setelah ");
                 System.out.print(years);
                 System.out.print(" tahun adalah Rp. ");
                 System.out.print(principal);
          } // end of while loop
          } // end of main()
       } // end of Class Interest
arip
arip
Pejuang
Pejuang

Jumlah posting : 36
Registration date : 05.03.09

Kembali Ke Atas Go down

Kembali Ke Atas

- Similar topics

 
Permissions in this forum:
Anda tidak dapat menjawab topik