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
FREE BRAINLIEST!!!
Nastasia [14]

Answer:

B

Explanation:

4 0
3 years ago
Read 2 more answers
Which statement best describes the computers all around us?
Advocard [28]

Answer:

B

Explanation:

we are in a digital generation, where by technology is gradually taking over the world. Almost all business, schools, company, etc make use of computer.

8 0
1 year ago
Free up disk space by doing____?​
8090 [49]

Answer:

Deleting files and etc on your computer.

6 0
3 years ago
Read 2 more answers
Complete the sentence.<br><br> A ___________search can be done on a list that is not ordered.
adelina 88 [10]

Answer:

Well, a binary search has to be ordered. So ima just say linear search..

Explanation:

I think its linear..

3 0
3 years ago
Read 2 more answers
Need the answer ASAP!!! I’ll mark brainliest if correct
san4es73 [151]

Answer:

update standerds

Explanation:

7 0
3 years ago
Other questions:
  • A(n) ____ is an attack that takes advantage of a system vulnerability.
    7·1 answer
  • What is heaven backwards?
    11·2 answers
  • In cryptography, the term "Secret algorithm" refers to an algorithm designed in a way that prevents the examination of its inner
    12·2 answers
  • Courts are struggling with the privacy implications of GPStracking. In 2009, New York’s highest court held that policeofficers m
    8·1 answer
  • Which of the following might cause a shift from PPF1 to PPF2? I. A new source of high quality denim fabric. II. A new lighter me
    12·1 answer
  • How can you stretch or skew an object in paint
    12·2 answers
  • Three different numbers need to be placed in order from least to greatest. For example, if the numbers are ordered 9, 16, 4, the
    15·1 answer
  • What is the ls option to list entries by lines instead of by columns?​
    11·1 answer
  • In which of the following stages of the development process is a team MOST likely to interview a potential user of an app?
    6·1 answer
  • Which are ways that technology keeps you hooked?
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!