Advertisement
ultravibez

Untitled

Oct 17th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.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 count = 0;
  12.         int max = 0;
  13.         int min = 0;
  14.         int index = 0;
  15.         int[] nums = new int[10];
  16.         int[] temp = new int[10];
  17.         boolean check = true;
  18.         while (select != 4) {
  19.             System.out.println("Please choose an option:");
  20.             System.out.println("1. Enter a number:");
  21.             System.out.println("2. Print the greatest number.");
  22.             System.out.println("3. Print the smallest number.");
  23.             System.out.println("4. Exit program.");
  24.             System.out.println("5. Print all the numbers.");
  25.             System.out.println("6. Clear all the numbers.");
  26.             select = scanner.nextInt();
  27.             if (input > max)
  28.                 max = input;
  29.             if (input < min)
  30.                 min = input;
  31.  
  32.             switch (select) {
  33.                 case 1:
  34.                     if (count > nums.length - 1)
  35.                         System.out.println("You can't print any more numbers.");
  36.                     else {
  37.                         System.out.print("Enter an integer: ");
  38.                         input = scanner.nextInt();
  39.                         nums[count] = input;
  40.                         count++;
  41.                     }
  42.                     if (count > nums.length)
  43.                         System.out.println("You can't print any more numbers.");
  44.                     if (check) {
  45.                         min = input;
  46.                         max = input;
  47.                         check = false;
  48.                     }
  49.                     if (max < input)
  50.                         index++;
  51.                     break;
  52.                 case 2:
  53.                     if (check) {
  54.                         System.out.println("You must enter a number first!");
  55.                     } else {
  56.                         System.out.println(max);
  57.                         for (int i = index; i < count; i++) {
  58.                             nums[i] = nums[i + 1];
  59.                         }
  60.                         nums[count] = 0;
  61.                         count--;
  62.                         max = 0;
  63.                         for (int i = 0; i < count; i++) {
  64.                             if (nums[i] > max) {
  65.                                 max = nums[i];
  66.                                 index = i;
  67.                             }
  68.                         }
  69.                     }
  70.                     break;
  71.                 case 3:
  72.                     if (check) {
  73.                         System.out.println("You must enter a number first!");
  74.                     } else
  75.                         System.out.println(min);
  76.                     break;
  77.                 case 4:
  78.                     System.out.println("The program will now exit, bye!");
  79.                     break;
  80.                 case 5:
  81.                     if (count == 0) {
  82.                         System.out.println("No numbers entered.");
  83.                         min = 0;
  84.                         max = 0;
  85.                         check = true;
  86.                     }
  87.                     for (int i = 0; i < count; i++) {
  88.                         System.out.print(i == count - 1 ? nums[i] : nums[i] + ",");
  89.                     }
  90.                     System.out.println("");
  91.                     break;
  92.                 case 6:
  93.                     for (int i = 0; i < nums.length; i++) {
  94.                         nums[i] = 0;
  95.                     }
  96.                     count = 0;
  97.                     System.out.println("All the numbers deleted.");
  98.                     break;
  99.                 default:
  100.                     System.out.println("Invalid number!");
  101.                     break;
  102.             }
  103.         }
  104.     }
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement