In the Bellow code I am supposed to find the month that correlates with the largest number.
Bellow is what I tried. However I belive that there is likly a more consice way to write this. How can I make it that way?
public class HelloWorld{
static int[] array = {3,6,7,3,2,30,9,13,12,1,2,1};
static String[] month = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
static int greatestVal = 0;
static int greatestVal2 = 0;
static String monthChosen = "";
int integer = 0;
static int num = 0;
public static void main(String []args){
int number = -1;
for (int i = 0; i<=11; i++) {
int currentValue = array[i];
number += 1;
//System.out.println(currentValue);
for (int index = 0; index <=11; index++) {
if (currentValue > array[index]) {
greatestVal = currentValue;
// System.out.println(currentValue +">"+ array[index]);
if (greatestVal > greatestVal2) {
greatestVal2 = greatestVal;
monthChosen = month[number];
}
} else {
// System.out.print("Hgfhdssdgfadkhfdshkjhads");
}
}
}
System.out.println(greatestVal2 + " greatest month is: " + monthChosen);
}
}