daily pastebin goal
14%
SHARE
TWEET

Untitled

a guest Aug 10th, 2018 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package ScannerFindMinAndMaxValue;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class FinderScanner {
  6.  
  7.  
  8.     public static void main(String[] args) {
  9.  
  10.  
  11.         Scanner scanner = new Scanner(System.in);
  12.  
  13.         int num1;
  14.         int num2;
  15.         int num3;
  16.         int num4;
  17.         int num5;
  18.  
  19.         System.out.println("Enter 1st number");
  20.         num1 = scanner.nextInt();
  21.         System.out.println("Enter 2nd number");
  22.         num2 = scanner.nextInt();
  23.         System.out.println("Enter 3rd number");
  24.         num3 = scanner.nextInt();
  25.         System.out.println("Enter 4th number");
  26.         num4 = scanner.nextInt();
  27.         System.out.println("Enter 5th number");
  28.         num5 = scanner.nextInt();
  29.  
  30.         int tab[] = {num1, num2, num3, num4, num5};
  31.  
  32.         int minimal = tab.length;
  33.         int maximal = tab.length;
  34.  
  35.         for (int i = 0; i < tab.length; i++) {
  36.             if (tab[i] < minimal) {
  37.                 minimal = tab[i];
  38.             }
  39.         }
  40.         System.out.println("The smallest number is: " + minimal);
  41.  
  42.         for (int i = 0; i < tab.length; i++) {
  43.             if (tab[i] > maximal) {
  44.                 maximal = tab[i];
  45.             }
  46.         }
  47.         System.out.println("The biggest number is: " + maximal);
  48.  
  49.     }
  50. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top