Write a method that returns index of the smallest element

Assignment Help Basic Computer Science
Reference no: EM13162873

Write a method that returns the index of the smallest element in an array of integers. If the number of such elements is greater than 1, return the smallest index. Use the following header:


public static int indexOfSmallestElement(double[] array)

Write a test program that prompts the user to enter ten numbers, invokes this method to return the index of the smallest element, and displays the index.

 

I've entered the following - But am receiving errors that note the void interferes with int. Please explain what the error is and how I can correct it. Thanks very much

 

 

import java.util.Scanner;

public class small{

 

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

double[] list = new double[10];

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

System.out.printf("Enter the number for index %d : ",i);

list[i] = sc.nextDouble();

}

 

int smallI= indexOfSmallestElement(list);

double smallE = list[smallI];

System.out.println();

System.out.printf("The smallest element is %.2f and its index is %d.\n",smallE,smallI);

 

}

 

public static void int indexOfSmallestElement (double[] array) {

double currentValue = array[0];

int smallestIndex = 0;

for (int j=1; j < arrSize ; j++) {

if (array[j] < currentValue)

{

currentValue = array[j];

smallestIndex = j;

}

}

}

 

 

 

Reference no: EM13162873

Questions Cloud

Explain how knowledge of the evaluator : Explain how knowledge of the evaluator (future employer) should influence a person’s writing of the resume or cover letter.
Why is it possible to separate the product : Why is it possible to separate the product (6-ethoxycarbonyl-3,5-diphenyl-2-cyclohexenone) from sodium hydroxide using acetone?
What is the maximum amount of silver : What is the maximum amount of silver (in grams) that can be plated out of 4.8 {rm L} of an {rm{AgNO}}_3 solution containing 3.6 % {rm Ag} by mass? Assume that the density of the solution is 1.01.
State the hydrolysis using bond energies : Calculate ?Hºrxn for the hydrolysis using bond energies. c. Why are the two values relatively close for the hydration in part "a" but not close for the hydrolysis in part "b"?
Write a method that returns index of the smallest element : Write a method that returns the index of the smallest element in an array of integers
Calculate the mass percent of a solution : Calculate the mass percent of a solution that is prepared by adding 40.0 g of rm NaOH to 408 g of {rm H_2O}.
State what is the percent ionization : What is the percent ionization of a 0.186 M solution of this acid? A certain weak base has a Kb of 7.50 × 10-7. What concentration of this base will produce a pH of 10.06?
Compute and flote 4 average temperature profiles : Generate by measdata.m an array A withsize (365,24), containing temperature measurements for an entire year [1 January,..., 31 December], 24 hours a day [00.00h,...,23.00h].
Compute the equilibrium concentration of the species : A solution is made by mixing exactly 500 mL of 0.180 M NaOH with exactly 500 mL of 0.100 M CH3COOH. Calculate the equilibrium concentration of the species

Reviews

Write a Review

Basic Computer Science Questions & Answers

  Identifies the cost of computer

identifies the cost of computer components to configure a computer system (including all peripheral devices where needed) for use in one of the following four situations:

  Input devices

Compare how the gestures data is generated and represented for interpretation in each of the following input devices. In your comparison, consider the data formats (radio waves, electrical signal, sound, etc.), device drivers, operating systems suppo..

  Cores on computer systems

Assignment : Cores on Computer Systems:  Differentiate between multiprocessor systems and many-core systems in terms of power efficiency, cost benefit analysis, instructions processing efficiency, and packaging form factors.

  Prepare an annual budget in an excel spreadsheet

Prepare working solutions in Excel that will manage the annual budget

  Write a research paper in relation to a software design

Research paper in relation to a Software Design related topic

  Describe the forest, domain, ou, and trust configuration

Describe the forest, domain, OU, and trust configuration for Bluesky. Include a chart or diagram of the current configuration. Currently Bluesky has a single domain and default OU structure.

  Construct a truth table for the boolean expression

Construct a truth table for the Boolean expressions ABC + A'B'C' ABC + AB'C' + A'B'C' A(BC' + B'C)

  Evaluate the cost of materials

Evaluate the cost of materials

  The marie simulator

Depending on how comfortable you are with using the MARIE simulator after reading

  What is the main advantage of using master pages

What is the main advantage of using master pages. Explain the purpose and advantage of using styles.

  Describe the three fundamental models of distributed systems

Explain the two approaches to packet delivery by the network layer in Distributed Systems. Describe the three fundamental models of Distributed Systems

  Distinguish between caching and buffering

Distinguish between caching and buffering The failure model defines the ways in which failure may occur in order to provide an understanding of the effects of failure. Give one type of failure with a brief description of the failure

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd