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
Bruce realizes he's getting a cramp in his neck after texting with his buddy for several minutes. he puts the phone down and tak
Arlecino [84]

Answer:Tech Neck

Explanation:

Tech Neck is when you are looking down to a phone for too long and you get a cramp in your neck

6 0
1 year ago
Which of the following statements is false? A constructor is similar to a method but is called implicitly by the new operator to
Volgvan

COMPLETE QUESTION:

Which of the following statements is false?

A) A constructor is similar to a method but is called implicitly by the new operator to initialize an object's instance variables at the time the object is created.

B0 Scanner method next reads characters until any white-space character is encountered, then returns the characters as a String.

C)A class instance creation expression begins with keyword new and creates a new object.

D) To call a method of an object, follow the object name with a comma, the method name and a set of parentheses containing the method's arguments.

Answer:

D) To call a method of an object, follow the object name with a comma, the method name and a set of parentheses containing the method's arguments.

Explanation:

To call a method, the name of the object is not followed by a comma (,) but with a dot (.) operator, the method's name and a set of parentheses containing the method's arguments, then follows.

4 0
3 years ago
Which view is most often used to reorder slides in a presentation that has already been created?
riadik2000 [5.3K]

Answer:

Normal view

Explanation:

The normal view is best used because it is just to drag and drop

4 0
3 years ago
Read 2 more answers
Which arcade game was co-created by steve jobs and steve wozniak?
Charra [1.4K]

Answer:

Breakout

Explanation:

5 0
3 years ago
Which option lists the correct steps to apply a style?
pav-90 [236]

Explanation:

b is answer l think is the ans

8 0
4 years ago
Other questions:
  • Write the pseudo code to display the largest number from given 3 numbers.(n1,n2,n3,).
    10·1 answer
  • What common objects you think will benefit from embedded computers?
    15·1 answer
  • What component of a computer system holds the operating system when the computer is not running
    6·2 answers
  • What's the best way to change the font size of all your notes pages at once?
    14·2 answers
  • A(n) _____ uses spatial and nonspatial data and specialized techniques for storing coordinates of networks of lines (roads, rive
    8·1 answer
  • Https://intro.edhesive.com/courses/17288/assignments/2313298?module_item_id=4864185
    9·1 answer
  • Explain URL's parts with the help of an example.​
    10·1 answer
  • Find the quotient. 2.5 ÷ 5
    8·2 answers
  • My chrome book computer clock is an hour off how do I fix that
    14·1 answer
  • Write a paragraph discussing privacy issues on the internet<br> and their impact on human lives.
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!