Hello everybody , I did an assignment for my java class and would like to have some input ; I have to create a program using a two dimensional array and average the high and the low numbers separatly and then return the largest and lowest index of the array . This is what I got so far
public class EC { static final int High =12; // 12 months in a year static final int Low = 12; // 12 months in a year public static void main(String[] args) { int[][] Temp ={{78,83,98,67,64,87,45,59,98,75,82,68}, // Array of Low Temperature {454,674,632,3265,62,478,54,428,23,76,65,45}}; //Array of High Temperature GetData(Temp); System.out.println(); averageHigh(Temp); System.out.println(); averageLow(Temp); System.out.println(); indexHighTemp(Temp); System.out.println(); indexLowTemp(Temp); System.out.println(); } // reads and store the data public static void GetData(int matrix[][] ) { int row, col; for (row = 0; row < matrix.length; row++) { for (col = 0; col < matrix[0].length; col++); } } // calculate the average high temperature of the year public static void averageHigh(int x[][] ){ int row, col = 1; int sum = 0; row= 1 ; for (col=0;col<x[row].length;col++) sum = sum +x[row][col]; System.out.print("The Average of High is " +sum/12); } // calculate the average low temperature of the year public static void averageLow(int x[][] ){ int row, col = 0; int sum = 0; row= 0; for (col=0;col<x[row].length;col++) sum = sum +x[row][col]; System.out.print("The Average of Low is " +sum/12); } // return index of the highest temperature public static void indexHighTemp(int x[][] ){ int max = x[0][0]; for (int row = 0; row < x.length; row++) { for (int col = 0; col < x[0].length; col++) { if (x[row][col] > max) { max = x[row][col]; } } } System.out.println("The largest index of the Array is "+max); } // return index of the lowest temperature public static void indexLowTemp(int x[][] ){ int idx =-1; int d= x[0][0]; for(int row = 0; row < x.length; row++) for (int col = 0; col < x[0].length; col++) if(x[row][col] < d) { idx = x[row][col]; } System.out.println("The largest index of the Array is "+idx); } }
Is this look good or do I have to change anything ?
Thanks