Question

how do i do this in basic java without using hashmat or anything complicated Two-Dimensional Arrays....

how do i do this in basic java without using hashmat or anything complicated

Two-Dimensional Arrays. Write the three functions described below. Demonstrate that your code works by calling each function and printing out the results. All of your code should be in one file. Upload your java code and a file containing the output of running your program to show that it works.

Write a function called create2DIntArray that creates a two-dimensional array of integers between 0 and 10. The array should have r rows and c columns. Both r and c are passed to the function. The function should return the address of the array that it creates.

Write a function called getMax2D that return the highest value in a two-dimensional array that is passed to the function.

Write a function called indexOFRow2D that returns the row that a target value is found in or it returns -1 if target is not in the array. The array and target are passed to the function.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.Random;

public class TwoDimensionalArrays {

public static void main(String[] args) {

int arr[][] = create2DIntArray(5, 5);

int max = getMax2D(arr);

System.out.println("Max element in 2D array : " + max);

int tar = 5;

int index = indexOFRow2D(arr, tar);

System.out.println("Index of " + tar + " in 2D array " + index);

}

private static int indexOFRow2D(int[][] aArr, int tar) {

for (int i = 0; i < aArr.length; i++)

for (int j = 0; j < aArr[i].length; j++) {

if (aArr[i][j] == tar) {

return i;

}

}

return -1;

}

private static int getMax2D(int[][] aArr) {

int max = -1;

for (int i = 0; i < aArr.length; i++)

for (int j = 0; j < aArr[i].length; j++) {

if (aArr[i][j] > max) {

max = aArr[i][j];

}

}

return max;

}

private static int[][] create2DIntArray(int aI, int aI2) {

int arr[][] = new int[aI][aI2];

Random r = new Random();

for (int i = 0; i < aI; i++) {

for (int j = 0; j < aI2; j++) {

arr[i][j] = r.nextInt(11);

}

}

return arr;

}

}

Console 3 <terminated> TwoDimensionalArrays [Java Application] C:Program FilesJavajre1.8.0_144 Max element in 2D array 10 Index of 5 in 2D array 3

Add a comment
Know the answer?
Add Answer to:
how do i do this in basic java without using hashmat or anything complicated Two-Dimensional Arrays....
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
  • Write a method that takes in a two-dimensional array of integers, do some calculation for each...

    Write a method that takes in a two-dimensional array of integers, do some calculation for each row in the two-dimensional array, and returns a one-dimensional array of sums for each row. Your code must work any array dimensions, including jagged arrays. The calculations are: • Sum of each row • Maximum value of each row • Minimum value of each row • Average of each row Here is an example an array passed and returns an array of sums for...

  • JAVA HELP (ARRAYS) Assignment Create a class named Module4 containing the following data members and methods...

    JAVA HELP (ARRAYS) Assignment Create a class named Module4 containing the following data members and methods (note that all data members and methods are for objects unless specified as being for the entire class) 1) Data members: none 2) Methods a. A method named displayContents that accepts an array of type int and prints their values to the b. A method named cemoveNegatives that accepts an array of type int, copies all its non-negative the new array should be the...

  • Using Java: 1. Recursive Multiplication Write a recursive function that accepts two arguments into the parameters...

    Using Java: 1. Recursive Multiplication Write a recursive function that accepts two arguments into the parameters x and y. The function should return the value of x times y. Remember, multiplication can be performed as repeated addition as follows: 5×6=6+6+6+6+6 2. Recursive findings Write a recursive boolean method named reFinding. The method should search an array for a specified value, and return true if the value is found in the array, or false if the value is not found in...

  • Using Java. Write a program that creates a “triangular” two-dimensional array A of 10 rows. The...

    Using Java. Write a program that creates a “triangular” two-dimensional array A of 10 rows. The first row has length 1, the second row has length 2, the third row has length 3, and so on. Then initialize the array using nested for loops so that the value of A[i][j] is i+j. Finally, print out the array in a nice triangular form.

  • Java Objective: The goal of this assignment is to practice 2-dimensional ragged arrays. Background: Within a...

    Java Objective: The goal of this assignment is to practice 2-dimensional ragged arrays. Background: Within a healthy, balanced diet, a grownup needs 2,250 calories a day You will write a program to track calorie intake of a person. Assignment: Calorie intake data from a person is provided in a text file named input.txt. There are arbitrary number of double values on each line, separated by spaces. The numbers represent the number of calories consumed for meals and/or snacks on a...

  • Write a java code that Declares and initialize a two-dimensional int array named grades. It should...

    Write a java code that Declares and initialize a two-dimensional int array named grades. It should have 10 rows and 6 columns where it stores the values and then calculates the average of all the elements in the grades array that you have declared

  • Please solve only if you know how to do it. Write the code using C++ (not...

    Please solve only if you know how to do it. Write the code using C++ (not Python or Java). Show and explain everything neatly. COMMENTS (7.5% of programming assignment grade): Your program should have at least ten (10) different detailed comments explaining the different parts of your program. Each individual comment should be, at a minimum, a sentence explaining a particular part of your code. You should make each comment as detailed as necessary to fully explain your code. You...

  • Language C Code Write a program that takes two integer arrays (A and B) and sums...

    Language C Code Write a program that takes two integer arrays (A and B) and sums them together (element wise). A third array to accept the result should be passed in as the output argument. Assume the arrays are all the same size. The argument N is the size of the arrays. Your code should provide a function with the following signature: void array Addition (int A[], int B[], int N, int output[]) { } Your code must also provide...

  • C++ Write a program to calculate the sum of two matrices that are stored inside two-dimensional...

    C++ Write a program to calculate the sum of two matrices that are stored inside two-dimensional arrays. Your program should include three functions: one for getting input data, one for calculating the sum of matrices, and one for printing the result. a) Function inputMatrix: This Function prompts the user to enter the data and stores data inside two-dimensional array. b) Function addMatrices: This function calculatesthe sum result of two matrices. c) Function printMatrix: This function prints the matrix to screen....

  • write C code that uses pointers, arrays, and C strings. 3. Write a function called pow_xy....

    write C code that uses pointers, arrays, and C strings. 3. Write a function called pow_xy. The function should be passed 2 parameters, as illustrated in the prototype below. int pow_xy(int *xptr, int y); Assuming that xptr contains the address of variable x, pow_xy should compute x to the y power, and store the result as the new value of x. The function should also return the result. Do not use the built-in C function pow. For the remaining problems,...

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