Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ueb05;
- import com.sun.media.sound.InvalidFormatException;
- import java.util.Scanner;
- public class Ueb05 {
- public static void main(String[] args) {
- double[] zahlen = new double[3];
- boolean eingabe = true;
- int i = 0;
- Scanner SC = new Scanner(System.in);
- System.out.println("Bitte den Benzinpreise angeben");
- while (i < zahlen.length && eingabe) {
- String input = SC.nextLine();
- System.out.println(i);
- if (input.toUpperCase().equals("x")) {
- eingabe = false;
- }
- else {
- try {
- double Preis = Double.parseDouble(input);
- if (Preis >= 1 && Preis <= 2) {
- zahlen[i] = Preis;
- i++;
- } else {
- System.out.println("Es wurde ein ungueltiger Preis eingegeben!");
- }
- } catch (NumberFormatException e) {
- System.out.println("");
- }
- }
- }
- if (zahlen.length == 3) {
- eingabe = false;
- }
- if (eingabe == false) {
- System.out.format("Anzahl der Preise: %d%n", zahlen.length);
- double kleinsteZahl = zahlen[0];
- for (int j = 1; j < zahlen.length; j++) {
- if (zahlen[j] < kleinsteZahl) {
- kleinsteZahl = zahlen[j];
- }
- }
- System.out.format("Kleinster Preis: %1.2f%n", kleinsteZahl);
- double größteZahl = zahlen[0];
- for (int g = 1; g < zahlen.length; g++) {
- if (zahlen[g] > größteZahl) {
- größteZahl = zahlen[g];
- }
- }
- System.out.format("Höchster Preis: %1.2f%n", größteZahl);
- double summe = zahlen[0];
- for (int h = 1; h < zahlen.length; h++) {
- summe += zahlen[h];
- }
- summe = summe / zahlen.length;
- System.out.format("Mittelwert: %1.2f%n", summe);
- double spanne;
- spanne = größteZahl - kleinsteZahl;
- System.out.format("Spanne: %1.2f%n", spanne);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement