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
Kaylis [27]
3 years ago
11

g (Locate the largest element) Write the following method that returns the location of the largest element in a two-dimensional

array: public static int [] locateLargest(double [][] a) The return value is a one-dimensional array that contains two elements. These two elements indicate the row and column indices of the largest element in the two-dimensional array. Write a test program (the main method) that prompts the user to enter a two-dimensional array and displays the location of the largest element of the array.
Computers and Technology
1 answer:
ruslelena [56]3 years ago
8 0

Answer:

The method in JAVA is shown below.

static double largest = 0.0;

   static int[] idx = new int[2];

   public static int r = 20;

   public static int c = 20;

   public static int[] locateLargest(double[][] a)

   {

       for(int j=0; j<c; j++)

 {

     for(int k=0; k<r; k++)

     {

         if(largest<a[j][k])

         {

             largest=a[j][k];

             idx[0]=k;

             idx[1]=j;

         }

     }

 }

 return idx;

   }

The JAVA program is shown below.

import java.util.Scanner;

import java.lang.*;

class program

{

   //static variables declared and initialized as required

   static double largest = 0.0;

   static int[] idx = new int[2];

   public static int r = 20;

   public static int c = 20;

   public static int[] locateLargest(double[][] a)

   {

       for(int j=0; j<c; j++)

 {

     for(int k=0; k<r; k++)

     {

         if(largest<a[j][k])

         {

             largest=a[j][k];

             idx[0]=k;

             idx[1]=j;

         }

     }

 }

 return idx;

   }

}

public class Main

{

   static double[][] arr;

   static double input;

   public static void main(String[] args){

       program ob = new program();

       arr = new double[ob.r][ob.c];

    Scanner sc = new Scanner(System.in);

 for(int j=0; j<ob.c; j++)

 {

     for(int k=0; k<ob.r; k++)

     {

         arr[j][k]=0;

     }

 }

 System.out.println("Enter the elements of two dimensional array ");

 for(int j=0; j<ob.c; j++)

 {

     for(int k=0; k<ob.r; k++)

     {

         input = sc.nextDouble();

         if(input>0)

          {   arr[j][k] = input;

          //System.out.println(arr[j][k]);

          }

         else

             break;

     }

     break;

 }

 int[] large_idx = ob.locateLargest(arr);

       int row = large_idx[0];

 int col = large_idx[1];

 double l = arr[col][row];

 System.out.println("The largest element in the user entered array is " + l);

}

}

OUTPUT

Enter the elements of two dimensional array  

1

2

3

4

5

6

7

8

9

0

The largest element in the user entered array is 9.0

Explanation:

1. The class program contains the locateLargest() method as mentioned in the question.

2. The public class Main contains the main() method.

3. User input for array is taken inside main().

4. This array is passed to the locateLargest() method.

5. This method returns the one dimensional array having row and column indices of the largest element in the array.

6. The indices are used to display the largest element in the main().

You might be interested in
Lief wants to keep the information of his chart, but he doesn’t want it taking up space in his page. What should he select after
Murljashka [212]
If wants to keep the chart but does not want it taking up space, he can move it  to another sheet. Once he goes to the Move Chart tab, he should select New Sheet which will ask for a name of the new sheet. After doing this, the chart will be moved to a different sheet.
4 0
3 years ago
Read 2 more answers
12. In 2009, __________ of all pedestrian fatalities were caused by impaired drivers
makvit [3.9K]
3% of pedestrian fatalities were caused by impaired drivers  
4 0
3 years ago
Read 2 more answers
In response to an alert regarding a possible security incident, you are analyzing the logs for a web application. In the process
SOVA2 [1]

The type of attack was most likely attempted against the application is an  XSS attack.

<h3>Why is the above an  XSS attack?</h3>

This attack is known to be an example of an XSS attack as it is one that is often recorded by the log of a web server's log.

Conclusively, Note that in this attack, if you see the HTML encoding, one can say that is mainly an XSS attack but when you see SQL or XML statements in the string, then it is another.

Learn more about attack from

brainly.com/question/76529

#SPJ1

4 0
2 years ago
Describe how you would define the relation Brother-in-Law whose tuples have the form (x, y) with x being the brother-in-law of y
damaskus [11]

Answer:

The expression is :

π[cd) + π(g,h) ],[π(e,f)+π(a,b)])

We will use foreign key and primary key

8 0
3 years ago
A smart refrigerator can use what to detect when you are running low on milk, and then send a reminder to you on a wireless
yulyashka [42]

Answer:

Internet of things

Explanation:

Smart refrigerators are equipped with IoTs which helps to sense when one is running low on milk and sends a reminder through a wireless connection.

Internet of things is connectivity or network of things.

  • It involves connection of different computing everyday devices which are able to interact with one another.
  • They have found a wide range of application in our hospitals, homes, and even work places.
  • The connectivity allows for more flexible controls and interaction wherever one might be with different components.
  • It uses a network of objects that exchanges data intermittently.
7 0
3 years ago
Other questions:
  • Using the CPI to calculate the inflation rate​ _______________ the underlying inflation​ rate, and using the core inflation rate
    7·2 answers
  • Welcome to Cypres...
    6·1 answer
  • What kind of fragment is near the computer?
    14·1 answer
  • What does an animation sequence action do?
    12·2 answers
  • When using a line graph, why is it important to only graph 1-3 series of data?
    14·1 answer
  • Complete the following statement: Sustainability is: Choose all that apply.This task contains the radio buttons and checkboxes f
    10·1 answer
  • Write c++ program from 1to 100 to find prime numbers using statement.<br><br>please help me​
    15·1 answer
  • Can someone be my friend,don't friend me until i ask you Questions
    14·1 answer
  • Consider the following code segment:
    12·1 answer
  • If you want to load the "my-data.csv" file to Dataframe so that you can explore find out the number of data items in the data se
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!