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);
}
}
Note: Please copy the Yellow color bold highlighted code.
Program Screenshot:
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);
}
}
IN JAVA Task: Find the maximum value and minimum value in milesTracker. Assign the maximum value...
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...
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 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; //...
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...
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...
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...
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; ...
USE JAVA Using recursion, find the largest element in an array. Skeleton code is provided. Please do not change the DataSetDemo code. Hint: Find the largest element in the subset containing all but the last element. Then compare that maximum to the value of the last element. Skeleton Code: DataSet: /** Computes the maximum of a set of data values. */ public class DataSet { private int[] values; private int first; private int last; /** Constructs a DataSet object. @param...
Can someone explain me parts of this code I do not fully understand what its doing or what its purpose is. I have highlighted the parts I'm confused over. Please explain thoroughly. import java.util.Scanner; class A1Stats { public static void main(String args[]) { double min, max, sum, mean; int n; Scanner scanner = new Scanner(System.in); String input = scanner.nextLine(); String[] numbers = input.split(" "); double value[] = new double[numbers.length]; if(numbers.length > 0){ for (int i = 0; i < numbers.length;...
Review the two programs listed below. Take part of the program and create a method or methods. Include methods in the program and execute. Temps.java // This program reads in a sequence of hourly temperature // readings (beginning with midnight) and prints the maximum // temperature (along with the hour, on a 24-hour clock, it / occurred) and the minimum temperature (along with the hour // it occurred) import java.util.Scanner; public class Temps public static void main (String[] args) final...