Concept explainers
What output is produced by the following code?
int[][] testArray = new int[3][4];
for (int row = 0; row < testArray.length; row++)
for (int col = 0;
col < testArray[row].length; col++)
testArray[row][col] = col;
for (int row = 0; row < testArray.length; row++)
{
for (int col = 0;
col < testArray[row].length; col++)
System.out.print(testArray[row][col] + " ");
system.out.println();
}
Want to see the full answer?
Check out a sample textbook solutionChapter 7 Solutions
Java: An Introduction to Problem Solving and Programming (7th Edition)
Additional Engineering Textbook Solutions
Starting Out with Python (4th Edition)
Starting Out with Programming Logic and Design (4th Edition)
Starting Out with C++ from Control Structures to Objects (8th Edition)
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
C Programming Language
Database Concepts (7th Edition)
- Suppose that longitude is assigned to the first column of an array and latitude is assigned to the second column of an array. If the user inputs the longitude and the latitude, how do you loop through the 2D array to find which row the longitude and latitude match up? Please use java to answer this question. Here are the variables: double longitude = Double.parseDouble(args[0]); double latitude = Double.parseDouble(args[1]);arrow_forwardimplement this function: chunk(array, size) ? Do not mutate the input array! ? Parameters array - Any JavaScript Array size - A positive integer Number indicating the desired "chunk" size. Return Value A new Array of Arrays. Each sub-Array has a length equal to size. Remaining elements are gathered into a final sub-Array. Do not use Array.prototype.slice in your implementation.Do not use Array.prototype.shift in your implementation.Do not use Array.prototype.pop in your implementation.Do not use Array.prototype.splice in your implementation. Examples chunk(['foo', 'bar', 'baz', 'qux'], 2); // -> [["foo", "bar"], ["baz", "qux"]] chunk([1, 2, 3, 4, 5], 1); // -> [[1], [2], [3], [4], [5]]chunk([false, true, false, true], 3); // -> [[false, true, false], [true]]chunk([], 7); // -> []arrow_forwardWrite a program called Range_array.java that has a method with one integer array and two integers position1 and position2 as parameters, where 0<=position1<=position2<=a.length-1. The method should construct and return an array that is identical to the given array, but with the values in position1 through position2 deleted. The output should look exactly like what is pictured below please. The code must be editable, and all variables defined within please.arrow_forward
- Consider 2 integer arrays, x and y, each with size equal to 10.Initialize array x with random numbers between 1 and 100.Write code that fills array y with values such that each element of y is the corresponding valueof x multiplied by its index.arrow_forwardIn Java Write an application that inputs five numbers, each between 10 and 100, inclusive. As each number is read, display it only if it’s not a duplicate of a number already read. Provide for the “worst case,” in which all five numbers are different. Use the smallest possible array to solve this problem. Display the complete set of unique values input after the user enters each new value. Rough output in screenshotarrow_forwardFor Java , Use for loops to fill in a 2-D array called grid2 that contains the following data (Note this is an array with 7 rows and 9 columns!):// 1 2 3 4 5 6 7 8 9 // 9 8 7 6 5 4 3 2 1// 1 2 3 4 5 6 7 8 9// 9 8 7 6 5 4 3 2 1// 1 2 3 4 5 6 7 8 9// 9 8 7 6 5 4 3 2 1// 1 2 3 4 5 6 7 8 9arrow_forward
- You are given two int variables j and k, an int array zipcodeList that has been declared and initialized, and a boolean variable duplicates. Write some code that assigns true to duplicates if any two elements in the array have the same value, and that assigns false to duplicates otherwise. Use only j, k, zipcodeList, and duplicates. this is a java programarrow_forwardWrite the following java code: Declare an array of int int myArray [] = { 4, 3, 2, 4, 8, 7, 5, 6, 2, 4, 7, 9, 5, 3, 7, 1}; Using an enhanced for loop, print how many elements are greater than 5(count).arrow_forwardYou are given an int variable k, an int array zipcodeList that has been declared and initialized, an int variable nZips that contains the number of elements in zipcodeList, and a bool variable duplicates. Write some code that assigns true to duplicates if there are two adjacent elements in the array that have the same value, and that assigns false to duplicates otherwise. Use only k, zipcodeList, nZips, and duplicates. duplicates = false; for (k=0; !duplicates && k<nZips-1; k++)if (zipcodeList[k] == zipcodeList[k+1]) duplicates = true;arrow_forward
- Do the Random2DArray And the tester is at the bottom import java.util.Random; /** * Store a 2-D array and provide methods to * get the average values of any row, any * column, or the entire array. * * Step 1: Enter your name for @author and today's date for @version * @author * @version */ public class Random2DArray { public final int LOW_LIMIT = -10; public final int HIGH_LIMIT = 10; // Step 2: Declare an instance variable of a 2-D // array of int // Step 3: Complete the constructor /** * Constructs an object of class Random2DArray * by initializing the instance variable to * the passed in parameter. * * @param array a 2-D array of int */ public Random2DArray(int[][] array) { } // Step 4: Complete the constructor /** * Constructs an object of class Random2DArray. * It creates a 2-D array of int with the * specified rows and columns for the instance *…arrow_forwardI am trying to write a code that swaps 1st element of an array with 2nd one, 3rd with 4th and keeps like that. It is not working and instead I wrote a code that is reversing the order. (better explanation on pictures attached.) I am using Java. public static void swapPairs(String[]array) {for(int i= 0; i< array.length / 2; i++) {int j= array.length - i -1;swap(array, i, j);}}public static void swap(String[] array, int i, int j) {String temp= array[i];array[i]= array[j];array[j]= temp;}arrow_forwardGiven an array temps of double, containing temperature data, and an int variable n that contains the number of elements in temps: Compute the average temperature and store it in a variable called avgTemp. Besides temps, n, and avgTemp, you may use only two other variables -- an int variable k and a double variable total, which have been declared.arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education