Question

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; // Assign with first element in milesTracker before loop
int minMiles = 0; // 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 */

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

Note: Please copy the Yellow color bold highlighted code.

Program Screenshot:

ArraysKeyValue.java import java.util.Scanner: //Declare the class public class ArraysKeyValue //main method public static void main (String [] args) final int NUM ROWS = 2; final int NUM COLS2; int [ ] [ ] milesTracker = new int [NUM ROWS ] [NUM COLS); int i 0; int j = 0; int maxMiles-0; // Assign with first element in milesTracker before loop int minMiles = 0; // Assign with first element in mīlesTracker before ïoop milesTracker [0] [0] =-10; milesTracker [0] [1]-20; milesTracker [1] [0] = 30; milesTracker [1] [1] = 40;Sample output:

Code to be copied:

import java.util.Scanner;

//Declare the class

public class ArraysKeyValue

{

      //main method

      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; // Assign with first element in milesTracker before loop

            int minMiles = 0; // 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*/

           

            // set the first element as maxMiles in milesTracker before loop

            maxMiles = milesTracker[0][0];

           

            // set the first element as minMiles milesTracker before loop

            minMiles = milesTracker[0][0];

            //Using two for-loops to compute the maxMiles

            for(i = 0; i < NUM_ROWS; ++i){

                  for(j = 0; j < NUM_COLS; ++j){

                        if(milesTracker[i][j] > maxMiles)

                        {

                              maxMiles = milesTracker[i][j];

                        }

                  }

            }

            //Using two for-loops to compute the minMiles

            for(i = 0; i < NUM_ROWS; ++i)

            {

                  for(j = 0; j < NUM_COLS; ++j)

                  {

                        if(milesTracker[i][j] < minMiles)

                        {

                              minMiles = milesTracker[i][j];

                        }

                  }

            }

           

            //Print the max and min miles

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

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

      }

}

Add a comment
Know the answer?
Add Answer to:
IN JAVA Task: Find the maximum value and minimum value in milesTracker. Assign the maximum value...
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
  • 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...

  • 7.9.1: Find 2D array max and min. Find the maximum value and minimum value in milesTracker....

    7.9.1: Find 2D array max and min. 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...

  • 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...

  • 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; //...

  • For any element in keysList with a value smaller than 60, print the corresponding value in...

    For any element in keysList with a value smaller than 60, print the corresponding value in itemsList, followed by a space. Ex: If keysList = {32, 105, 101, 35} and itemsList = {10, 20, 30, 40}, print: 10 40 import java.util.Scanner; public class ArraysKeyValue {    public static void main (String [] args) {       final int SIZE_LIST = 4;       int[] keysList = new int[SIZE_LIST];       int[] itemsList = new int[SIZE_LIST];       int i;       keysList[0] = 13;      ...

  • Write a loop that subtracts 1 from each element in lowerScores. If the element was already...

    Write a loop that subtracts 1 from each element in lowerScores. If the element was already 0 or negative, assign 0 to the element. Ex: lowerScores = {5, 0, 2, -3} becomes {4, 0, 1, 0}. import java.util.Scanner; public class StudentScores { public static void main (String [] args) { Scanner scnr = new Scanner(System.in); final int SCORES_SIZE = 4; int[] lowerScores = new int[SCORES_SIZE]; int i; for (i = 0; i < lowerScores.length; ++i) { lowerScores[i] = scnr.nextInt(); }...

  • 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...

  • need help editing or rewriting java code, I have this program running that creates random numbers...

    need help editing or rewriting java code, I have this program running that creates random numbers and finds min, max, median ect. from a group of numbers,array. I need to use a data class and a constructor to run the code instead of how I have it written right now. this is an example of what i'm being asked for. This is my code: import java.util.Random; import java.util.Scanner; public class RandomArray { // method to find the minimum number in...

  • package Lab11; import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; public class Lab10 {    public...

    package Lab11; import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; public class Lab10 {    public static void main (String [] args)    {    // ============================================================    // Step 2. Declaring Variables You Need    // These constants are used to define 2D array and loop conditions    final int NUM_ROWS = 4;    final int NUM_COLS = 3;            String filename = "Input.txt";    // A String variable used to save the lines read from input...

  • I need help asking the user to half the value of the displayed random number as...

    I need help asking the user to half the value of the displayed random number as well as storing each number generated by the program into another array list and displayed after the game is over at the end java.util.*; public class TestCode { public static void main(String[] args) { String choice = "Yes"; Random random = new Random(); Scanner scanner = new Scanner(System.in);    ArrayList<Integer> data = new ArrayList<Integer>(); int count = 0; while (!choice.equals("No")) { int randomInt =...

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