Java :: Aufgabe #261
2 Lösungen
Preise im Copy-Shop für Kopien
Anfänger - Java
von DragStar
- 20.03.2020 um 11:53 Uhr
In einem Copy-Shop gilt folgende Preisliste:
01 - 49 Seiten kostet 0,10 Euro pro Seite
50 - 99 Seiten kostet 0,09 Euro pro Seite
100 - 199 Seiten kostet 0,08 Euro pro Seite
ab 200 Seiten kostet 0,06 Euro pro Seite
Erstellen Sie ein Programm, welches nach Eingabe der Anzahl der Kopien den Gesamtpreis ausgibt.
01 - 49 Seiten kostet 0,10 Euro pro Seite
50 - 99 Seiten kostet 0,09 Euro pro Seite
100 - 199 Seiten kostet 0,08 Euro pro Seite
ab 200 Seiten kostet 0,06 Euro pro Seite
Erstellen Sie ein Programm, welches nach Eingabe der Anzahl der Kopien den Gesamtpreis ausgibt.
Lösungen:
Java-Code
import java.util.Scanner; class Scratch { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); float sum; System.out.println("Wie viele Kopien?"); int copies = scanner.nextInt(); if (copies <= 49) { sum = (float) (copies * 0.10); System.out.println("Betrag: " + sum + " Euro"); } else if (copies <= 99) { sum = (float) (copies * 0.09); System.out.println("Betrag: " + sum + " Euro"); } else if (copies <= 199) { sum = (float) (copies * 0.08); System.out.println("Betrag: " + sum + " Euro"); } else { sum = (float) (copies * 0.06); System.out.println("Betrag: " + sum + " Euro"); } } }
Java-Code
import java.util.*; public class main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("Wie viele Kopien dürfen es sein?"); int anzahl = sc.nextInt(); if (anzahl < 50) { System.out.print("Das macht "+ anzahl*0.1 +" Euro!"); } else { if (anzahl < 100) { System.out.print("Das macht "+anzahl*0.09+" Euro!"); } else { if (anzahl < 200) { System.out.print("Das macht "+anzahl*0.08+" Euro!"); } else { System.out.print("Das macht "+anzahl*0.06+" Euro!"); } } } } }