Advertisement
ultravibez

Homework Mike

Oct 16th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.85 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Main {
  6.  
  7.     public static void main(String[] args) {
  8.         Scanner scanner = new Scanner(System.in);
  9.         int select = 0;
  10.         int input = 0;
  11.         int max = 0;
  12.         int min = 0;
  13.         boolean first = true;
  14.         while (select != 4) {
  15.             System.out.println("Please choose an option:");
  16.             System.out.println("1. Enter a number: ");
  17.             System.out.println("2. Print the greatest number");
  18.             System.out.println("3. Print the smallest number");
  19.             System.out.println("4. Exit program.");
  20.             select = scanner.nextInt();
  21.  
  22.             if (input > max)
  23.                 max = input;
  24.             if (input < min)
  25.                 min = input;
  26.  
  27.             switch (select) {
  28.                 case 1:
  29.                     System.out.print("Enter an integer: ");
  30.                     input = scanner.nextInt();
  31.                     if (first) {
  32.                         min = input;
  33.                         max = input;
  34.                         first = false;
  35.                     }
  36.                     break;
  37.                 case 2:
  38.                     System.out.println(max);
  39.                     if (first) {
  40.                         System.out.println("Please enter a first number");
  41.                     }
  42.                     break;
  43.                 case 3:
  44.                     System.out.println(min);
  45.                     if (first) {
  46.                         System.out.println("Please enter a first number");
  47.                     }
  48.                     break;
  49.                 case 4:
  50.                     System.out.println("The program will now exit, bye!");
  51.                     break;
  52.                 default:
  53.                     System.out.println("Invalid number");
  54.                     break;
  55.             }
  56.         }
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement