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
which of the following sentences uses active voice?(answers to choose from are in the photo)-this is in my computer applications
andrezito [222]
Last week, Nate and I counted all the inventory. answer :A
6 0
3 years ago
Read 2 more answers
A typical, small, dry cell battery has a voltage of A. 6.0 volts. B. 1.0 volts. C. 12.0 volts. D. 1.5 volts.
Bad White [126]
The answer is D 1.5 volts
6 0
3 years ago
Read 2 more answers
Someone please help ASAP will brainlist
Arada [10]

Answer:

i cant help

Explanation:

4 0
3 years ago
Read 2 more answers
What does "FDDI" stand for in Technology?
Komok [63]
Pretty sure it's Fiber Distributed Data Interface
6 0
4 years ago
Read 2 more answers
Write a program that asks the user to input an integer named numDoubles. Create a dynamic array that can store numDoubles double
Hitman42 [59]

Answer:

Answered in C++

#include <iostream>

using namespace std;

int main() {

   int size;

   cout<<"Length of array: ";

   cin >> size;

   double *numDoubles = new double[size];

   double sum =0;

   cout<<"Array Elements: ";

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

       cin>>numDoubles[i];

       sum += numDoubles[i];

   }

   delete [] numDoubles;

   cout<<"Average: "<<sum/size;

   return 0;  

}

Explanation:

This line declares the size (or length) of the array

<em>    int size; </em>

This line prompts the user for the array length

<em>    cout<<"Length of array: "; </em>

This gets the input from the user

<em>    cin >> size; </em>

This dynamically declares the array as of double datatype

<em>    double *numDoubles = new double[size]; </em>

This declares and initializes sum to 0

<em>    double sum =0; </em>

This prompts the user for elements of the array

<em>    cout<<"Array Elements: "; </em>

The following iteration gets input from the user and also calculates the sum of the array elements

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

<em>        cin>>numDoubles[i]; </em>

<em>        sum += numDoubles[i]; </em>

<em>    } </em>

This deletes the array

<em>    delete [] myarray; </em>

This calculates and prints the average of the array

<em>    cout<<"Average: "<<sum/size; </em>

6 0
3 years ago
Other questions:
  • I need some cool things to do with windows command prompt.
    13·1 answer
  • Financial goals are helpful because they
    7·1 answer
  • Which of the following questions will most likely be answered by displaying data on a line graph?
    14·1 answer
  • Group technology identifies components by a coding scheme that specifies the
    13·1 answer
  • Why do generated backup scripts usually include backticks around names such as database names and column names?
    5·1 answer
  • You may see the term FAQ on websites which stands for Frequently Asked Questions this is an example of which type of mnemonic?
    9·1 answer
  • Handouts are pages of your presentation that you print and distribute to your audience
    10·1 answer
  • On a computer with two or more cpus, ____ is a technique in which each processor or core works on a different job.
    15·1 answer
  • GIVING 50 POINTS!
    6·2 answers
  • What would the theoretical variance (square of the standard deviation) of the following random values be? rand(Normal(80, 10), 2
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!