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
what type of authentication does the dod require to accesss sensitive data on mobile devices and /or email
nikklg [1K]
Dod required a car to access data gahagsgssgsg
3 0
3 years ago
Read 2 more answers
Do we have to use intersection?
levacccp [35]
Yessssssssssssssssssss
8 0
3 years ago
Write a Python program string_functions.py that defines several functions. Each function re-implements Python's built-in string
Svetach [21]

Answer:

def length( mystring):

   count = 0

   for i in mystring:

       count += 1

   return count

def reversed( mystring):

   strlist = []

   for i in range(length(mystring)):

       strlist.append(mystring[(length(mystring) - 1) - i])

       txt = "".join(strlist)

   return txt

string = 'Yolanda'

print(reversed(string))

Explanation:

The python module defines two functions 'reversed' and 'length'. The length function counts the number of characters in a string variable while the reversed function reverses the string variable value.

3 0
2 years ago
What is the synonym for term port?
Rus_ich [418]
The synonym for term port is seaport

3 0
3 years ago
Write about storage<br>(should be in easy words)​
enyata [817]

Answer:

Answer to the following question is as follows;

Explanation:

The process of storing digital information in a data storage media using computing technology is known as storage. Storage is a technique that allows a computer to keep data indefinitely or intermittently. Computer storage capacity and electronic data management are other terms for storage.

6 0
2 years ago
Other questions:
  • Candace opened an email from a person she didn't know and clicked on a pop-up in the email that installed a virus on her compute
    8·2 answers
  • All of the following are stages in the SDLC except _____.
    9·1 answer
  • Write a loop that reads positive integers from standard input and that terminates when it reads an integer that is not positive.
    10·1 answer
  • To quit Word, click the Restore button on the right side of the title bar. <br> True <br> False
    6·1 answer
  • When naming a file to upload into an assignment in blackboard, it is okay to use special characters?
    13·1 answer
  • The smallest building block of a wireless lan is a ______.
    5·1 answer
  • What was the technology that defined each of the four generations of computers?
    12·1 answer
  • What element is not a selection in the Interface preferences? UI Character Presets UI Font Size UI Language UI Scaling
    9·1 answer
  • Fifty part-time students were asked how many courses they were taking this term. The (incomplete) results are shown below. Need
    6·1 answer
  • Develop a program that will maintain an ordered linked list of positive whole numbers. Your program will provide for the followi
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!