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
opearating system protection refers to a mechanism for controling access by programs, processes, or users to both system and use
Alekssandra [29.7K]

Answer:

The operating system must by the use of policies define access to and the use of all computer resources.

Policies are usually defined during the design of the system. These are usually default in settings. Others are defined and or modified during installation of the addon and or third-party software.

Computer Security Policies are used to exact the nature and use of an organisations computers systems. IT Policies are divided into 5 classes namely:

  1. General Policies
  2. Server Policies
  3. VPN Policies
  4. Back-Up Policies
  5. Firewall Access and Configuration Policies

Cheers!

5 0
3 years ago
Display flight number, origin, destination, fl_orig_time as --"Departure Time", fl_dest_time as "Arrival Time". Format times in
NARA [144]

Answer:

Select "flight number", origin, destination, format(fl_orig_time, 'HH:mm' ) as "Departure Time", format(fl_dest_time, 'HH:mm') as "Arrival Time" from table_name order by flight_number

Explanation:

The script is used to select records from the table named 'table_name' and formatted to 24hr time format with the hour in capital letters (signifying 24 hrs). Then the inverted comma used for flight number is due to the space character ebtween the two words. In a select statement, order by comes after the table name. While as is used as an alias for a column in a table.

8 0
2 years ago
To all paladins players out there!!!!!
Alex777 [14]

I am BORED PPL ..........

Explanation:

hi

6 0
3 years ago
A program written in a(n) procedural language consists of sequences of statements that manipulate data items. __________________
Alenkasestr [34]

Answer:

true.

Explanation:

According to my research on information technology, I can say that based on the information provided within the question the statement is completely true. Procedural programming is a widely used paradigm that basically gives the program a set of routines or specifications, and the program mixes and matches them as they continuously repeat the process. It is used in many areas, including video game development.

I hope this answered your question. If you have any more questions feel free to ask away at Brainly.

7 0
3 years ago
has anyone noticed to get credit for answering a question you don't even need to answer it correctly?
Helga [31]

Yes I've noticed this. Unfortunately it's up to the user (Asker) to report an answer incorrect.

8 0
3 years ago
Read 2 more answers
Other questions:
  • Desktop computer systems are less reliable than laptop computers. <br> a. True <br> b. False
    9·1 answer
  • What career cluster does a fish and game warden fall in?
    14·1 answer
  • A machine on a 10 Mbps network is regulated by a token bucket algorithm with a fill rate of 3 Mbps. The bucket is initially fill
    12·1 answer
  • The study of a current business and information system application and the definition of user requirements and priorities for a
    5·1 answer
  • If you are going to refer to a few dozen classes in your application, how do<br> you do it?
    6·1 answer
  • What is the value of numX when this program is executed? if 3 &lt; 5 and 8 != 3: numX = 3 else: numX = 7
    13·2 answers
  • Which of the following are NOT possible using the RANDOM(a, b) and DISPLAY(expression) abstractions?
    10·1 answer
  • Heather writes an essay for language arts and receives a poor grade. To figure out why she gets a poor grade, Heather looks at t
    14·2 answers
  • What are two advantages of a pay-for-use online conferencing service compared to a free service? (Choose two)
    5·1 answer
  • Which game would you play info you were competitive?
    13·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!