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 count = 0;
- int max = 0;
- int min = 0;
- int index = 0;
- int[] nums = new int[10];
- int[] temp = new int[10];
- boolean check = 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.");
- System.out.println("5. Print all the numbers.");
- System.out.println("6. Clear all the numbers.");
- select = scanner.nextInt();
- if (input > max)
- max = input;
- if (input < min)
- min = input;
- switch (select) {
- case 1:
- if (count > nums.length - 1)
- System.out.println("You can't print any more numbers.");
- else {
- System.out.print("Enter an integer: ");
- input = scanner.nextInt();
- nums[count] = input;
- count++;
- }
- if (count > nums.length)
- System.out.println("You can't print any more numbers.");
- if (check) {
- min = input;
- max = input;
- check = false;
- }
- if (max < input)
- index++;
- break;
- case 2:
- if (check) {
- System.out.println("You must enter a number first!");
- } else {
- System.out.println(max);
- for (int i = index; i < count; i++) {
- nums[i] = nums[i + 1];
- }
- nums[count] = 0;
- count--;
- max = 0;
- for (int i = 0; i < count; i++) {
- if (nums[i] > max) {
- max = nums[i];
- index = i;
- }
- }
- }
- break;
- case 3:
- if (check) {
- System.out.println("You must enter a number first!");
- } else
- System.out.println(min);
- break;
- case 4:
- System.out.println("The program will now exit, bye!");
- break;
- case 5:
- if (count == 0) {
- System.out.println("No numbers entered.");
- min = 0;
- max = 0;
- check = true;
- }
- for (int i = 0; i < count; i++) {
- System.out.print(i == count - 1 ? nums[i] : nums[i] + ",");
- }
- System.out.println("");
- break;
- case 6:
- for (int i = 0; i < nums.length; i++) {
- nums[i] = 0;
- }
- count = 0;
- System.out.println("All the numbers deleted.");
- break;
- default:
- System.out.println("Invalid number!");
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement