Question

Find the maximum value and minimum value in milesTracker. Assign the maximum value to maxMiles, and...

Find the maximum value and minimum value in milesTracker. Assign the maximum value to maxMiles, and the minimum value to minMiles. Sample output for the given program:

Min miles: -10
Max miles: 40

import java.util.Scanner;

public class ArraysKeyValue {
public static void main (String [] args) {
Scanner scnr = new Scanner(System.in);
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

for (i = 0; i < milesTracker.length; i++){
for (j = 0; j < milesTracker[i].length; j++){
milesTracker[i][j] = scnr.nextInt();
}
}

//solution goes here

System.out.println("Min miles: " + minMiles);
System.out.println("Max miles: " + maxMiles);
}
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1
import java.util.Scanner;
public class ArraysKeyValue {
    public static void main (String [] args) {
        Scanner scnr = new Scanner(System.in);

        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

        for (i = 0; i < milesTracker.length; i++){
          for (j = 0; j < milesTracker[i].length; j++){
            milesTracker[i][j] = scnr.nextInt();
          }
        }

        maxMiles = milesTracker[0][0];
        minMiles = milesTracker[0][0];

        for(i = 0;i<NUM_ROWS;i++){
            for(j = 0;j<NUM_COLS;j++){
                if(minMiles > milesTracker[i][j]){
                    minMiles = milesTracker[i][j];
                }
                if(maxMiles < milesTracker[i][j]){
                    maxMiles = milesTracker[i][j];
                }
            }
        }

        System.out.println("Min miles: " + minMiles);
        System.out.println("Max miles: " + maxMiles);
    }
}
Add a comment
Know the answer?
Add Answer to:
Find the maximum value and minimum value in milesTracker. Assign the maximum value to maxMiles, and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • IN JAVA Task: Find the maximum value and minimum value in milesTracker. Assign the maximum value...

    IN JAVA Task: Find the maximum value and minimum value in milesTracker. Assign the maximum value to maxMiles, and the minimum value to minMiles. Sample output for the given program: Min miles: -10 Max miles: 40 Given Code: 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 = 0; int j = 0; int maxMiles = 0;...

  • IN C PLEASE Find the maximum value and minimum value in miles Tracker. Assign the maximum...

    IN C PLEASE Find the maximum value and minimum value in miles Tracker. Assign the maximum value to maxMiles, and the minimum value to minMiles. Sample output for the given program: Min miles: -10 Max miles: 40 (Notes) 1 tes pass ㄷ Alltes int j; 1 #include <stdio.h> 2 3 int main(void) { 4 const int NUM_ROWS = 2; 5 const int NUM_COLS = 2; 6 int milesTracker [NUM_ROWS] [NUM_COLS]; 7 int i; 8 9 int maxMiles = 0; //...

  • Find the maximum value and minimum value in milesTracker. Assign the maximum value to maxMiles, and...

    Find the maximum value and minimum value in milesTracker. Assign the maximum value to maxMiles, and the minimum value to minMiles. Sample output for the given program: Find the maximum value and minimum value in miles Tracker. Assign the maximum value to maxMiles, and the minimum value to minMiles. Sample output for the given program Min miles: -10 Max miles: 40 (Notes) 1 import java.util.Scanner 3 public class ArraysKeyValue 4 public static void main (String passe args) i final int...

  • 1. Assign numMatches with the number of elements in userValues that equal matchValue. userValues has NUM_VALS...

    1. Assign numMatches with the number of elements in userValues that equal matchValue. userValues has NUM_VALS elements. Ex: If userValues is {2, 1, 2, 2} and matchValue is 2 , then numMatches should be 3. Your code will be tested with the following values: matchValue: 2, userValues: {2, 1, 2, 2} (as in the example program above) matchValue: 0, userValues: {0, 0, 0, 0} matchValue: 10, userValues: {20, 50, 70, 100} What i am given: import java.util.Scanner; public class FindMatchValue...

  • Write a for loop to print all NUM_VALS elements of array hourlyTemp. Separate elements with a...

    Write a for loop to print all NUM_VALS elements of array hourlyTemp. Separate elements with a comma and space. Ex: If hourlyTemp = {90, 92, 94, 95}, print: 90, 92, 94, 95 Your code's output should end with the last element, without a subsequent comma, space, or newline. import java.util.Scanner; public class PrintWithComma {    public static void main (String [] args) {       Scanner scnr = new Scanner(System.in);       final int NUM_VALS = 4;       int[] hourlyTemp = new...

  • Feedback CHALLENGE ACTIVITY 3.8.1: Using boolean Assign is Teenager with true if kidAge is 13 to...

    Feedback CHALLENGE ACTIVITY 3.8.1: Using boolean Assign is Teenager with true if kidAge is 13 to 19 inclusive. Otherwise, assign is Teenager with false. 1 import java.util.Scanner; 3 public class TeenagerDetector { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); boolean isTeenager; int kidAge; kidAge - scnr.nextInt(); /* Your solution goes here */ if (isTeenager) { System.out.println("Teen"); else { System.out.println("Not teen"); 19 20 ) ) Run Feed CHALLENGE ACTIVITY 3.8.2: Boolean in branching statements. - r

  • CHALLENGE ACTIVITY 3.11.1: Using boolean. D Assign is Teenager with true if kidAge is 13 to...

    CHALLENGE ACTIVITY 3.11.1: Using boolean. D Assign is Teenager with true if kidAge is 13 to 19 inclusive. Otherwise, assign is Teenager with false. 1 import java.util.Scanner; 3 public class TeenagerDetector 1 public static void main (String [] args) { Scanner scnr = new Scanner(System.in); boolean isTeenager; int kidAge; D}]oll kidage = scnr.nextInt(); /* Your solution goes here */ Go USB if (isTeenager) { System.out.println("Teen"); else { System.out.println("Not teen"); 20 Run Feedback? CHALLENGE ACTIVITY 3.11.2: Boolean in branching statements. Write...

  • Complete the do-while loop to output 0 to countLimit. Assume the user will only input a...

    Complete the do-while loop to output 0 to countLimit. Assume the user will only input a positive number. import java.util.Scanner; public class CountToLimit { public static void main (String [] args) { Scanner scnr = new Scanner(System.in); int countLimit = 0; int printVal = 0; // Get user input countLimit = scnr.nextInt(); printVal = 0; do { System.out.print(printVal + " "); printVal = printVal + 1; } while ( /* Your solution goes here */ ); System.out.println(""); return; } }

  • Answer in JAVA 1. Complete the method definition to output the hours given minutes. Output for...

    Answer in JAVA 1. Complete the method definition to output the hours given minutes. Output for sample program: 3.5 import java.util.Scanner; public class HourToMinConv {    public static void outputMinutesAsHours(double origMinutes) {       /* Your solution goes here */    }    public static void main (String [] args) {       Scanner scnr = new Scanner(System.in);       double minutes;       minutes = scnr.nextDouble();       outputMinutesAsHours(minutes); // Will be run with 210.0, 3600.0, and 0.0.       System.out.println("");    } } 2....

  • *This needs comments for each line of code. Thanks in advance!* import java.util.Scanner; public class LabProgram...

    *This needs comments for each line of code. Thanks in advance!* import java.util.Scanner; public class LabProgram {     public static void main(String[] args) {         Scanner scnr = new Scanner(System.in);         int numCount = scnr.nextInt();         int[] Array = new int[numCount];                for(int i = 0; i < numCount; ++i) {             Array[i] = scnr.nextInt();         }         int jasc = Array[0], gws = Array[1], numbers, tempo;         if (jasc > gws) {             tempo = jasc;             jasc...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT