Create a program that will allow the user to input ten numbers into an array, using values of 0 to 99, and print out all numbers except for the largest number and the smallest number.
Sample Output:
Enter the Numbers >> 10 20 10 40 50 60 70 80 90 99
Output >> 20 40 50 60 70 80 90
Try Again Y/N?
import java.util.Scanner;
public class App {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String answer = "";
while (answer.compareToIgnoreCase("n") != 0) {
int[] numbers = new int[10];
System.out.print("Enter the Numbers >> ");
for (int i = 0; i < 10; i++) {
numbers[i] = in.nextInt();
}
int min = numbers[0];
int max = numbers[0];
for (int i = 0; i < 10; i++) {
if (min > numbers[i]) {
min = numbers[i];
}
if (max < numbers[i]) {
max = numbers[i];
}
}
System.out.print("Output >> ");
for (int i = 0; i < 10; i++) {
if (min != numbers[i] && max != numbers[i]) {
System.out.print(numbers[i] + " ");
}
}
in.nextLine();
System.out.print("\nTry Again Y/N? ");
answer = in.nextLine();
}
in.close();
}
}
Comments
Leave a comment