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
viktelen [127]
3 years ago
5

Write a program that prompts the user to enter the number of integer numbers you need to enter, then ask user to enter these int

eger numbers. Your program should contain an indexOfLargestElement method, which is used to return the index of the largest element in an array of integers.
Computers and Technology
1 answer:
nadya68 [22]3 years ago
8 0

Answer:

import java.util.Scanner;

public class Main

{

public static void main(String[] args) {

 Scanner ob = new Scanner(System.in);

 System.out.println("How many numbers? ");

 int n = ob.nextInt();

       int[] arr = new int[n];  

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

     System.out.print("Enter the number: ");

     arr[i] = ob.nextInt();

 }

    System.out.println(indexOfLargestElement(arr));

}

public static int indexOfLargestElement(int[] arr) {

    int max = arr[0];

    int maxIndex = 0;

    for (int i=0; i<arr.length; i++) {

        if (arr[i] >= max) {

            max = arr[i];

            maxIndex = i;

        }

    }

    return maxIndex;

}

}

Explanation:

Create a method called indexOfLargestElement that takes one parameter, an array

Initialize the max and maxIndex

Create a for loop iterates throgh the array

Check each element and find the maximum and its index

Return the index

Inside the main:

Ask the user to enter how many numbers they want to put in array

Get the numbers using a for loop and put them inside the array

Call the indexOfLargestElement method to find the index of the largest element in the array

You might be interested in
Lindsey also needs to calcite the commissions earned each month. If the company earns $200,000 or more in a month, the commissio
IrinaK [193]

Answer:

srry dont know

Explanation:

8 0
2 years ago
What is an embedded system. Give examples
IRINA_888 [86]

Answer:

An embedded system is a part of a larger system which has either one or a limited number of dedicated functions.

It doesn't require much power to run and is cheap to make and design.

Explanation:

Examples include: cars, microwaves, traffic lights, washing machines, phones etc

6 0
3 years ago
Most manual-transmission vehicles use a _______ to gauge engine speed in RPMs. A. variable valve timer B. tachometer C. torque i
gavmur [86]
I believe the answer is b. tachometer

5 0
3 years ago
A sample member of the list data is a1 = ['male', True] where the second item is True if the person is on the phone.
Ira Lisetskai [31]
Answer:

0

Explanation:
In the lists, indexation starts from 0, because of that in if statement we compare item[0] which is 'male' and 'male', and then males is itterated within for loop.
8 0
2 years ago
Read 2 more answers
What is the name of html command? ​
Makovka662 [10]

Here are some.

  • <html></html> This is the root element tag. ...
  • <head></head> ...
  • <title></title> ...
  • <body></body> ...
  • <h1></h1> ...
  • <p></p> ...
  • <a></a> ...
  • <img></img>
<h2>hope it helps.</h2><h2>stay safe healthy and happy....</h2>
3 0
2 years ago
Other questions:
  • In your presentation you added a text box to?
    5·1 answer
  • What information is required for a complete citation of a website source?
    8·2 answers
  • The cord of a bow string drill was used for
    14·1 answer
  • What is the color difference between the iMac and iMac Pro
    14·2 answers
  • Given a String variable response that has already been declared, write some code that repeatedly reads a value from standard inp
    10·1 answer
  • Write a python program that requests a positive integer from the user, determines if it is a composite, a prime or neither prime
    8·1 answer
  • What are the benefits of computer literacy?
    10·1 answer
  • 2.
    13·1 answer
  • How can the two independent clauses below be combined to form a correct complete sentence? Check all that apply.
    5·1 answer
  • Compare and discuss between electromechanical and electronic era of computer​
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!