Guest User

Untitled

a guest
Jan 22nd, 2019
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.89 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class Slide61_Oef2 {
  3.  
  4.  
  5.     public static void main(String[] args)
  6.     {
  7.         Scanner input=new Scanner(System.in);
  8.        
  9.         int getal, kleinst, grootst, aantal;
  10.        
  11.         System.out.print("Geef een getal (afsluiten door 0): ");
  12.         getal = input.nextInt();
  13.        
  14.         //initialisatie van de variabelen
  15.         kleinst = 2147483647;
  16.         grootst = -2147483647;
  17.         aantal = 0;
  18.        
  19.         while (getal != 0)
  20.         {
  21.             aantal += 1;
  22.            
  23.             if (getal > grootst)
  24.             {
  25.                 grootst = getal;
  26.             }
  27.            
  28.             if (getal < kleinst)
  29.             {
  30.                 kleinst = getal;
  31.             }
  32.            
  33.             System.out.print("Geef een getal (afsluiten door 0): ");
  34.             getal = input.nextInt();
  35.         }
  36.        
  37.         if (aantal == 0)
  38.         {
  39.             System.out.println("Er werden geen getallen ingegeven.");
  40.         }
  41.        
  42.         else
  43.         {
  44.             System.out.println("Het grootste getal is " + grootst);
  45.             System.out.println("Het kleinste getal is " + kleinst);
  46.         }
  47.  
  48.     }
  49.  
  50. }
Add Comment
Please, Sign In to add comment