Kurs:Java (Kjell)/Code-Rubrik/Wechselgeld.java
Erscheinungsbild
- Dollar.java
Programmcode
[Bearbeiten]package kapitel_10;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
class Wechselgeld {
public static void main (String[] args) throws IOException {
BufferedReader stdin =
new BufferedReader ( new InputStreamReader( System.in ) );
String inData;
int dollar, quarter, dime, nickel, cent;
System.out.println("Geben Sie die Cent ein:");
inData = stdin.readLine();
cent = Integer.parseInt(inData);
// Berechnungen
dollar = cent / 100;
cent = cent % 100;
quarter = cent / 25;
cent = cent % 25;
dime = cent / 10;
cent = cent % 10;
nickel = cent / 5;
cent = cent % 5;
System.out.println("Das Wechselgeld ist "+ dollar + " Dollar, "
+ quarter + " Quarter, "+ dime + " Dime, " + nickel
+ " Nickel und " + cent + " Cent.");
}
}