Answer:
The program in Java is as follows:
import java.util.*;
public class Main{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String [] salsa = {"Mild","Medium","Sweet","Hot","Zesty"};
int [] number = new int[5];
for(int i = 0;i<5;i++){
System.out.print(salsa[i]+" number: ");
number[i] = input.nextInt();
}
for(int i = 0;i<5;i++){
System.out.println(salsa[i]+" : "+number[i]);
}
int smallest = number[0]; int highest = number[0];
int count = 0;
for(int i = 0;i<5;i++){
if(smallest > number[i]){
smallest = number[i];
count = i;
}
}
System.out.println("Smallest");
System.out.println(salsa[count]+" : "+smallest);
for(int i = 0;i<5;i++){
if(highest < number[i]){
highest = number[i];
count = i;
}
}
System.out.println("Highest");
System.out.println(salsa[count]+" : "+highest);
}
}
Step-by-step explanation:
This initializes the salsa names
String [] salsa = {"Mild","Medium","Sweet","Hot","Zesty"};
This declares the array for the amount of salsa
int [] number = new int[5];
This iterates through the 5 salsas and get input for the amount of each
for(int i = 0;i<5;i++){
System.out.print(salsa[i]+" number: ");
number[i] = input.nextInt();
}
This prints each salsa and the amount sold
for(int i = 0;i<5;i++){
System.out.println(salsa[i]+" : "+number[i]);
}
This initializes smallest and largest to the first array element
int smallest = number[0]; int highest = number[0];
This initializes the index of the highest or lowest to 0
int count = 0;
The following iteration gets the smallest of the array elements
for(int i = 0;i<5;i++){
if(smallest > number[i]){
smallest = number[i];
This gets the index of the smallest
count = i;
}
}
This prints the smallest
System.out.println("Smallest");
System.out.println(salsa[count]+" : "+smallest);
The following iteration gets the largest of the array elements
for(int i = 0;i<5;i++){
if(highest < number[i]){
highest = number[i];
This gets the index of the highest
count = i;
}
}
This prints the highest
System.out.println("Highest");
System.out.println(salsa[count]+" : "+highest);