Advertisement
Guest User

Untitled

a guest
Jan 20th, 2020
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. package javaapplication2;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class dowhileminmax {
  6.  
  7. public static void main(String[] args) {
  8.  
  9. Scanner eingabe = new Scanner(System.in);
  10.  
  11. int eingabeZahl, anzahl, min, max;
  12.  
  13. anzahl = 1;
  14. max = 1;
  15. min = 1;
  16.  
  17. do {
  18. System.out.print(anzahl + " Wert eingeben: ");
  19. eingabeZahl = eingabe.nextInt();
  20. if (anzahl == 1){
  21. min = eingabeZahl;
  22. max = eingabeZahl;
  23. }
  24. anzahl ++;
  25.  
  26. if (eingabeZahl > max && eingabeZahl != 0) max = eingabeZahl;
  27. if (eingabeZahl < min && eingabeZahl != 0) min = eingabeZahl;
  28.  
  29. }while(eingabeZahl != 0);
  30.  
  31. System.out.println("Es wurden " + (anzahl - 2) + " Zahlen eingegeben");
  32. System.out.println("Maximum war " + max);
  33. System.out.println("Minumim war " + min);
  34. }
  35.  
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement