Jumat, 30 Desember 2011

prgram menghitung pecahan uang (dalam Java)

import java.util.Scanner;
public class uang
{
public static void main(String args[])
{
Scanner masuk = new Scanner(System.in);
int uang,U1=100000,U2=50000,U3=20000,U4=10000,U5=5000,U6=1000,U7=500;
int Sisa1,Sisa2,Sisa3,Sisa4,Sisa5,Sisa6;
int uang1, uang2, uang3, uang4, uang5, uang6, uang7;
System.out.print ("Masukkan jumlah uang : ");
uang = masuk.nextInt();

uang1 = uang/U1;
Sisa1 = uang%U1;

uang2 = Sisa1/U2;
Sisa2 = Sisa1%U2;

uang3 = Sisa2/U3;
Sisa3 = Sisa2%U3;

uang4 = Sisa3/U4;
Sisa4 = Sisa3%U4;

uang5 = Sisa4/U5;
Sisa5 = Sisa4%U5;

uang6 = Sisa5/U6;
Sisa6 = Sisa5%U6;

uang7 = Sisa6/U7;

System.out.println( "Uang 100000 : "+ uang1 );
System.out.println( "Uang 50000 : "+ uang2 );
System.out.println( "Uang 20000 : "+ uang3 );
System.out.println( "Uang 10000 : "+ uang4 );
System.out.println( "Uang 5000 : "+ uang5 );
System.out.println( "Uang 1000 : "+ uang6 );
System.out.println( "Uang 500 : "+ uang7 );

}
}

0 komentar:

Posting Komentar

Statistik

Translate

Blog Archive