1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
r-ruslan [8.4K]
3 years ago
12

The return value is a one-dimensional array that contains two elements. These two elements indicate the rows and column indices

of the largest element in the two-dimensional array. Write a test program that prompts the user to enter a two-dimensional array and displays the location of the largest element in the array.
Computers and Technology
1 answer:
erma4kov [3.2K]3 years ago
7 0

Answer:

In Java:

import java.util.Scanner;  

import java.util.Arrays;  

public class Main  {  

public static void main(String args[])  {  

Scanner input = new Scanner(System.in);

int row, col;  

System.out.print("Rows: ");    row = input.nextInt();

System.out.print("Cols: ");     col = input.nextInt();  

int[][] Array2D = new int[row][col];

System.out.print("Enter array elements: ");

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

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

        Array2D[i][j] = input.nextInt();  

    }     }

 

int[] maxarray = findmax(Array2D,row,col);

System.out.println("Row: "+(maxarray[0]+1));

System.out.println("Column: "+(maxarray[1]+1));

}  

public static int[] findmax(int[][] Array2D,int row, int col)   {  

int max = Array2D[0][0];

int []maxitem = new int [2];

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

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

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

            maxitem[0] = i;

            maxitem[1] = j; } }    }

 

return maxitem;  

}  

}

Explanation:

The next two lines import the scanner and array libraries

<em>import java.util.Scanner;   </em>

<em>import java.util.Arrays;   </em>

The class of the program

<em>public class Main  {  </em>

The main method begins here

<em>public static void main(String args[])  {  </em>

The scanner function is called in the program

<em>Scanner input = new Scanner(System.in);</em>

This declares the array row and column

int row, col;

This next instructions prompt the user for rows and get the row input  

System.out.print("Rows: ");    row = input.nextInt();

This next instructions prompt the user for columns and get the column input  

System.out.print("Cols: ");     col = input.nextInt();  

This declares the 2D array

int[][] Array2D = new int[row][col];

This prompts the user for array elements

System.out.print("Enter array elements: ");

The following iteration populates the 2D array

<em> for(int i =0;i<row;i++){    </em>

<em>     for(int j =0;j<col;j++){ </em>

<em>         Array2D[i][j] = input.nextInt();   </em>

<em>     }     } </em>

This calls the findmax function. The returned array of the function is saved in maxarray  

int[] maxarray = findmax(Array2D,row,col);

This prints the row position

System.out.println("Row: "+(maxarray[0]+1));

This prints the column position

System.out.println("Column: "+(maxarray[1]+1));

The main method ends here

}  

The findmax function begins here

public static int[] findmax(int[][] Array2D,int row, int col)   {  

This initializes the maximum to the first element of the array

int max = Array2D[0][0];

This declares maxitem. The array gets the position of the maximum element

int []maxitem = new int [2];

The following iteration gets the position of the maximum element

<em>for(int i =0;i<row;i++){ </em>

<em>     for(int j =0;j<col;j++){ </em>

<em>         if(Array2D[i][j] > max){  </em>

<em>             maxitem[0] = i; </em><em>-- The row position is saved in index 0</em><em> </em>

<em>             maxitem[1] = j;  </em><em>-- The column position is saved in index 1</em><em>} }    } </em>

This returns the 1 d array

return maxitem;  

}  

You might be interested in
When performing actions between your computer and one that is infected with a virus, which of the following offers NO risk of yo
Alexandra [31]

The one already infected, I think ..

6 0
3 years ago
50 Points being offered for the fastest and most correct response<br><br> How do I fix this?
kolezko [41]
Hi there!

Try resetting your browser, clearing your cache, and rebooting your computer.. If none of these work, or you've already tried these, let me know..

Hope this helps! ☺♥
5 0
3 years ago
Read 2 more answers
Following the car in front of you at a closer distance _____.
tiny-mole [99]

Answer:

B. Doesn’t get you to your location faster.

Explanation:

Following the car in front of you at a closer distance doesn’t get you to your location faster.

6 0
3 years ago
Read 2 more answers
Which delivery model is an example of a cloud computing environment that provides users with a web based email service ?
Evgen [1.6K]

Cloud computing, also known as cloud services, cloud concepts or simply the cloud, is a paradigm that allows to offer computer services. through a network, which is usually the Internet.

(data persistence, authentication, messaging, etc.). for example, a Linux system, a web server, and a programming environment such as Perl or Ruby).

Commercial examples are Google App ,Microsoft Azure,

3 0
3 years ago
Read 2 more answers
What kind of resources can we share over the network? Plzzzzzzzz help!!!!!!
lubasha [3.4K]

Sharing network resources requires abiding by certain constraints, as follows:

<span>Security: Organizations present ongoing opportunities for unauthorized shared resources. Security mechanisms should be implemented to provide efficient parameters.Compatibility: Various client-server operating systems may be installed, but the client must have a compatible OS or application to access shared resources. Otherwise, the client may encounter issues that create communication delays and requires troubleshooting.Mapping: Any shared OS hardware drive, file or resource may be accessed via mapping, which requires a shared destination address and naming conventions.<span>File Transfer Protocol (FTP) and File Sharing: FTP is not affected by shared resources because the Internet is FTP’s backbone. File sharing is an LAN concept.</span></span>
3 0
3 years ago
Read 2 more answers
Other questions:
  • Which graphic design tool allows you to lay images on top of one another? A. Layers B. Selection C. Drawing D. Color
    10·2 answers
  • _____________ is the characteristic of a resource that ensures that access is restricted to only permitted users, applications,
    14·1 answer
  • Read the scenario, and then answer the question that follows.
    10·1 answer
  • 2. Imagine you play a game of fetch with the dog. It takes the dog 60 seconds to run a total of 180 meters. What was the dog's a
    6·1 answer
  • I WILL MARK BRAINLIEST PLZ HELP
    5·1 answer
  • Why is it a good idea to leave an interview being courteous and polite?
    10·1 answer
  • Write a method drivingCost() with input parameters drivenMiles, milesPerGallon, and dollarsPerGallon, that returns the dollar co
    10·1 answer
  • Adam's interview with the hiring manager is going well. However, he wants to ensure that his skills and work history are memorab
    6·1 answer
  • I need some help with this assignment. I'm having difficulty trying come up ideas to use here. Can I get any help?
    5·1 answer
  • PLZ HELP I AM TIMED!!!!
    11·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!