I'm trying to display in the Message dialog on the JOptionPane
the highest number of sales from my array of sales.
And I also want to show in which month they happened, but I am failing to find a way to display the month.
public static void main(String[] args) {
int[] CarSales= {1234,2343,1456,4567,8768,2346,9876,4987,7592,9658,7851,2538};
String [] Months = {"January","February","March","April","May","June"
,"July ","August","September","October","November","December" };
int HighNum = CarSales[0];
for(int i = 0; i < CarSales.length; i++)
{
if(CarSales[i] > HighNum)
{
HighNum = CarSales[i];
}
}
JOptionPane.showMessageDialog(null,"The highest car sales value is :"+HighNum +
"-which happened in the month of");
}
There are multiple solutions but i'll give you the simplest based on your structure. Just declare one String variable and assign the value whenever you change the highest num.