Why does he say that the lowest number is always Null? I got confused, I tried to make a lot of changes, but I can’t understand what is wrong with him.
He gives me the correct highest number, but for the lowest he always prints on the console: the lowest sales were at zero
Here is my code:
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Scanner;
public class Project5 {
public static Scanner in = new Scanner(System.in);
public static HashMap<Integer, String> Months = new HashMap<Integer, String>();
public static ArrayList<Integer> SALES = new ArrayList<Integer>();
public static void main(String[] args) {
SALES.add(0,000);
addHash();
for(int i =1;i<=12;i++){
System.out.println("Enter sales for " + Months.get(i));
int value= in.nextInt();
SALES.add(i,value);
}
int max = Collections.max(SALES);
int maxIndex = SALES.indexOf(max);
System.out.println("Highest sales were in " + Months.get(maxIndex));
int min = Collections.min(SALES);
int minIndex = SALES.indexOf(min);
System.out.println("Lowest sales were in " + Months.get(minIndex));
for(int i=1;i<=12;i++){
System.out.println(Months.get(i) + ": " + SALES.get(i));
}
}
public static void addHash(){
Months.put(1,"January");
Months.put(2,"Feburary");
Months.put(3,"March");
Months.put(4,"April");
Months.put(5,"May");
Months.put(6,"June");
Months.put(7,"July");
Months.put(8,"August");
Months.put(9,"September");
Months.put(10,"October");
Months.put(11,"November");
Months.put(12,"December");
}
}
user5613751
source
share