Created
March 1, 2018 02:14
-
-
Save viveknarang/1d9e838e616692b71ca05e62eac5cbf9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
public class ArraysKeyValue { | |
public static void main (String [] args) { | |
final int NUM_ROWS = 2; | |
final int NUM_COLS = 2; | |
int [][] milesTracker = new int[NUM_ROWS][NUM_COLS]; | |
int i; | |
int j; | |
int maxMiles; // Assign with first element in milesTracker before loop | |
int minMiles; // Assign with first element in milesTracker before loop | |
milesTracker[0][0] = -10; | |
milesTracker[0][1] = 20; | |
milesTracker[1][0] = 30; | |
milesTracker[1][1] = 40; | |
/* Your solution goes here */ | |
maxMiles = Integer.MIN_VALUE; | |
minMiles = Integer.MAX_VALUE; | |
for (i = 0 ; i < milesTracker.length; i++) { | |
for (j = 0 ; j < milesTracker[0].length; j++) { | |
if (milesTracker[i][j] < minMiles) { | |
minMiles = milesTracker[i][j]; | |
} | |
if (milesTracker[i][j] > maxMiles) { | |
maxMiles = milesTracker[i][j]; | |
} | |
} | |
} | |
System.out.println("Min miles: " + minMiles); | |
System.out.println("Max miles: " + maxMiles); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment