public class Main {
public static void main(String[] args) {
String[] monthsArray = { "City/Month", "JAN", "FEB", "MAR" };
String[] citiesArray = { "JHB", "DBN", "CTN", "PE" };
int[][] speedsArray = { { 128, 135, 139 }, { 155, 129, 175 }, { 129, 130, 185 }, { 195, 155, 221 } };
for (int j = 0; j < monthsArray.length; j++) {
System.out.print(String.format("%-20s", monthsArray[j]));
}
System.out.println();
for (int i = 0; i < speedsArray.length; i++) {
System.out.print(String.format("%-20s", citiesArray[i]));
for (int j = 0; j < speedsArray[i].length; j++) {
System.out.print(String.format("%-20d", speedsArray[i][j]));
}
System.out.println();
}
System.out.println();
int lowest = Integer.MAX_VALUE;
int lowestRow = 0;
int lowestColumn = 0;
int highest = 0;
int highestRow = 0;
int highestColumn = 0;
for (int i = 0; i < speedsArray.length; i++) {
for (int j = 0; j < speedsArray[i].length; j++) {
if (speedsArray[i][j] > highest) {
highest = speedsArray[i][j];
highestRow = i;
highestColumn = j;
}
if (speedsArray[i][j] < lowest) {
lowest = speedsArray[i][j];
lowestRow = i;
lowestColumn = j;
}
}
}
System.out.println("The highest speeding is " + highest + "Km on month " + monthsArray[highestColumn + 1]
+ " from " + citiesArray[highestRow] + " city");
System.out.println("The lowest is " + lowest + "Km on month " + monthsArray[lowestColumn + 1] + " from "
+ citiesArray[lowestRow] + " city");
}
}
Comments
Leave a comment