Pagi ini saya akn membagikan tentang cara menghitung perubahan pada pemrograman java, . .
Silahkan dicoba, . .
import java.util.Scanner;
public class ComputeChange {
public static void main(String[] iriahus) {
@SuppressWarnings("resource")
Scanner s = new Scanner(System.in);
System.out.print("Enter an amount: ");
int amount = s.nextInt();
int dollar = amount / 100;
int quarter = amount % 100 / 25;
int dimes = amount % 100 % 25 / 10;
int nickels = amount % 100 % 25 % 10 / 5;
int pennies = amount % 5;
System.out.println("Your amount is " + amount + " consists of \n" +
"\t" + dollar + " dollars\n" +
"\t" + quarter + " quarters\n" +
"\t" + dimes + " dimes\n" +
"\t" + nickels + " nickels\n" +
"\t" + pennies + " pennies\n");
}
}
Semoga bermanfaat, . .
0 Response to "Menghitung Perubahan"
Post a Comment