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
Ex1. Classify the following statements as business (B), functional (F), non- functional (N), or data (D) requirements; for the l
Alina [70]

Answer:

<em>Solution</em>:

The statements are listed below.  

<em>(A) Functional requirement </em>

  • Functional specifications refer to the handling of calls.  
  • Minimum call number should be 3000, and a functional requirement.  

<em>(B) Non-functional requirement</em>

  • Non-functional requirement is the default option.  
  • Payment in "Visa" is required and this is not a functional requirement.

<em>(C) Data requirements</em>

  • Data requirements apply to quantity of order.  
  • When the quantity of data exceeds then an exception should be notified  

<em>(D) Business requirements. </em>

  • Product reviews are subject to business requirements.

3 0
2 years ago
Choose the correct term to complete the sentence.
Alex

Answer:

the answer to your question is obviously "rational"

3 0
2 years ago
IDENTIFYING VERBS THAT AGREE IN NUMBER WITH THEIR SUBJECTS For each of the following sentences, write the correct form of the ve
Novay_Z [31]

Hey there!

  • The word "<u>verb</u>" simply means <em>'description of an action, assert, or event that is made into the main purpose of your predicate in your judgement' </em>
  • Now that we have the definition of the word verb we can answer your question
  • "<em>Has</em>" is past tense but it is THIRD person present
  • "<em>Have</em>" is when you own something
<h2>Answer: HAS ✅</h2>

BECAUSE "I SAW last night"

Note: usually people read the sentence to themselves until it makes easier sense to them or use context clues in the sentence to answer the particular question(s)

Good luck on your assignment and enjoy your day!

~LoveYourselfFirst:)

6 0
3 years ago
Read 2 more answers
Case Project 2-1: The Differences Between IPv4 and IPv6 You are a network engineer for an IT consulting firm named F1IT. One of
Nadusha1986 [10]

Answer:

Following are the difference to this question:

Explanation:

IPv4:

The IPv_4 is uses the packet changed method, that is a Link Layer networks(like Ethernet).  It has 4.3 billion addresses capacity. It uses the 32-bit logical device address, that written in decimal language. It is divided by 4 bytes E.g. 192.168.1.1  

The host part and network part are 2 parts. For a network, the host part may vary, while for the entire subnet, the network part remains equal. The scheme of 232 addresses is available on application depends on security.

IPv6:

The IPv6 is used in the internet protocoland it is higher than IPv4. It can provide endless number Opf addresses, and use to solves the problem of IPv4 exhaustion and satisfies  the demand for rising networking.

IPv4 Substitutor Built to meet more IP address requirements. In the Logical address of 128-bit Written hexadecimally and with colons divided, and the Space of 128 addresses are required. IPsec is an integrated security feature.

5 0
3 years ago
How is the phrase "employability skills" defined?
Digiron [165]

Answer:

Problem-solving. Why is problem-solving so valued? Companies face a lot of obstacles. Those better able to cope

Explanation:

7 0
2 years ago
Read 2 more answers
Other questions:
  • Marie uses a browser to visit a blog. What is the unique identifier of the blog? A. web page B. website C. web address D. email
    7·2 answers
  • What is PHP language
    12·1 answer
  • NEED HELP ASAP! BRAINLIEST AND 20 PTS TO CORRECT ANSWER!
    14·1 answer
  • Bobbi owns a protein shake company, which has been trading for 3 years. Her products are stocked in a number of gyms, but the co
    11·1 answer
  • PLEASE HELP ANSWER THIS only if you know BOTH ANSWERS!
    9·2 answers
  • What is used to connect computers to the internet*Audio Ports
    15·2 answers
  • Which of the following is not a data visualization technique?
    6·1 answer
  • Give an example of what Artificial Intelligence application most popular is used on a daily basis.
    12·2 answers
  • If html is used to specify the content of the webpage, then what do you use css for?.
    12·1 answer
  • Choose the answer that best completes the visual analogy.
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!