Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int select = 0;
- int input = 0;
- int max = 0;
- int min = 0;
- boolean first = true;
- while (select != 4) {
- System.out.println("Please choose an option:");
- System.out.println("1. Enter a number: ");
- System.out.println("2. Print the greatest number");
- System.out.println("3. Print the smallest number");
- System.out.println("4. Exit program.");
- select = scanner.nextInt();
- if (input > max)
- max = input;
- if (input < min)
- min = input;
- switch (select) {
- case 1:
- System.out.print("Enter an integer: ");
- input = scanner.nextInt();
- if (first) {
- min = input;
- max = input;
- first = false;
- }
- break;
- case 2:
- System.out.println(max);
- if (first) {
- System.out.println("Please enter a first number");
- }
- break;
- case 3:
- System.out.println(min);
- if (first) {
- System.out.println("Please enter a first number");
- }
- break;
- case 4:
- System.out.println("The program will now exit, bye!");
- break;
- default:
- System.out.println("Invalid number");
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement