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

  Sbh problem to reconstruct dna sequence from its l-mer

The SBH problem is to reconstruct a DNA sequence from its l-mer composition. Suppose that instead of a single target DNA fragment, we have two target DNA fragments

  Report on explaining how to recover corrupt file

When you try to open the file in an image viewer, a message is displayed indicating that the file is corrupt. Write a 2-3 page report explaining how to recover the file, orkty.zip, for further investigation.

  Key principles on smart phone devices gps tracking system

How to apply these key principles on smart phone devices GPS tracking system/software to mitigate user personal information be exposed undesirably.

  Compute minimum-maximum possible values for distance

During run, compute the minimum and maximum possible values for the following distance measures (from the center of the track): Manhattan, Euclidean and Chebyshev distance.

  Determine throughput for file transfer form one host-another

Assume Host A wishes to send the large file to Host B. Suppose no other traffic in network, Determine the throughput for the file transfer?

  Find mean shopping time at supermarket-level of significance

Using 0.10 level of significance is there evidence that mean shopping time at local supermarket is different from claimed value of 22 minutes?

  Explaining reasonable values for items in risk register

Suggest reasonable values for the items in the risk register for this asset and threat, and provide justifications for your choices.

  Explain delimiter marks only beginning of comment

Delimiter marks only the beginning of the comment (for one line comments). Write the advantages and disadvantages of each of these with respect to our criteria.

  Create a plot of a cubic spline fit

Create a plot of a cubic spline fit of following data with natural end conditions: x 0 100 200 400f(x) 0 0.82436 1.00000 0.73576. compare the plot with the following equation which was used to create data.

  Statistics about the numbers read

Write a function whose job is to input #'s, non-# to quit, recover from the input failure by calling recover(), and tell main some statistics about the numbers read. . unsigned readA();

  Emerging technologies developments

Are you a optimistic or apprehensive about developments in emerging technologies that simulate human experience? Provide examples of a business condition that would benefit from each of the following?

  Explain how decision problem is decidable

Think of the way to mark all variables A such that for some string x ∈ Σ*, A (⇒*(over)G) x. Describe algorithm in detail.

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