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
he function below takes one parameter: a list of strings (string_list). Complete the function to return a new list containing on
Aleks04 [339]

Answer:

def select_short_strings(string_list):

   new_list = []

   

   for s in string_list:

       if len(s) < 20:

           new_list.append(s)

   return new_list

   

lst = ["apple", "I am learning Python and it is fun!", "I love programming, it is easy", "orange"]

print(select_short_strings(lst))

Explanation:

- Create a function called <em>select_short_strings</em> that takes one argument <em>string_list</em>

Inside the function:

- Initialize an empty list to hold the strings that are less than 20

- Inside the loop, check the strings inside <em>string_list</em> has a length that is smaller than 20. If found one, put it to the <em>new_list</em>.

- When the loop is done, return the <em>new_list</em>

- Create a list to check and call the function

4 0
3 years ago
Read 2 more answers
unlike tv or newspaper ads, internet communications are interactive, and consumers can choose which messages and information the
Softa [21]

Companies often engage the services of Advertising firms to market their products. Company web offerings can be tailor-made for the consumers.

  • Advertising agencies are firms that makes, plan and handle the advertising needs of any business. They are known for handling negotiations creating tailored marketing campaigns.

A lot of agencies do not want to talk about pricing until they know what you can afford to spend.

Tailored content are delivered experiences that speak directly to customers.

This agencies uses their connections and resources to make one's campaign successful and cost-efficient.

Learn more from

brainly.com/question/23477855

5 0
2 years ago
An indication of delayed fuel ignition could be​
Sophie [7]

Answer:

The ignition delay in a diesel engine is defined as the time interval between the start of injection and the start of combustion. This delay period consists of (a) physical delay, wherein atomisation, vaporization and mixing of air fuel occur and (b) of chemical delay attributed to pre-combustion reactions. Physical and chemical delays occur simultaneously.

Hope This Helps!     Have A Nice Day!!

6 0
3 years ago
____________________ are compromised systems that are directed remotely (usually by a transmitted command) by the attacker to pa
Talja [164]

Answer: Zombies

Explanation: Zombie is a computer device that is responsible for the compromising the system and making it prone to several destruction such as the Trojan horse virus,hackers and other viruses as well. Zombie makes the computer system to get malfunctioned easily ,that is without much security and various malicious functions can be performed.They basically act as the infected computer .

6 0
3 years ago
Read 2 more answers
Currently, the users in your company are required to use their IP addresses when connecting to other hosts. Since IP addresses a
Sonja [21]

Answer:

False

Explanation:

Using subnet mask will be helpful, what the subnet mask does is moving the IP address boundary bettween the part that represents a network and the part that represents a host, thus, instructing the operating system which IP addresses are on the local subnet. Then the operating will communicate directly with the other host without using the router. Once this is achieved, memorizing the IP addresses is needless.          

8 0
3 years ago
Other questions:
  • How many bits do you need to count up to 30 help please
    14·1 answer
  • To change the size of a field or record by dragging its border a.resize b.magnify c.label d.enlarge
    11·2 answers
  • If you are working in a word-processing program and need to learn more about its features, the best place to get assistance is f
    7·2 answers
  • A ____ appears at the bottom of your e-mail messages and contains standard information about yourself that the recipient can use
    5·1 answer
  • Processors for most mobile devices run at a slower speed than a processor in a desktop PC.
    9·2 answers
  • Who made the first sandwich?
    5·2 answers
  • Write the function powersOf3ToN(n) that takes a possibly-negative float or int n, and returns a list of the positive powers of 3
    10·1 answer
  • I need to reverse a inputted word using for loops with range 0 to the input word and increment 1.
    5·1 answer
  • ______________ are used to store information that will be referenced and manipulated in a computer program. They label data with
    6·1 answer
  • Explain with examples the roles of system software and application software?<br>​
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!