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

  Explain organizations pools markets and expertise

When output of some units can be used as inputs to othe units, or if two organizations pools markets and expertise which results in lower costs and generate profits it is frequently referred to as creating?

  Shortest path between each pair of nodes using floyd''s metho

find the shortest path between each pair of nodes using Floyd's method

  Determine the effective miss rate

For the following repeating sequence of 1w address (given in hex) and cache configurations... Assuming least recently used (LRU) replacement for associative caches,

  Explain animation schemes comprise slide transitions

Some animation schemes comprise slide transitions and some don't. When would the transition be suitable? When would it not be suitable?

  Write component which is part of lcd panel assembly

Write down three ways notebook can get its power? Write down component which is part of the LCD panel assembly might be responsible for LCD panel showing dim screens?

  Design patterns in today-s development environments

In System Analysis and Design: Design Patterns - How widely used are design patterns in today's development environments?

  Maximum speedup-achieved by pipeline over non-pipelined unit

Non-pipelined system takes 200ns to process task. Determine the maximum speedup that could be achieved with pipeline unit over the non-pipelined unit?

  What is meant by artificial intelligence

What is meant by artificial intelligence? What are two essential differences between human brains and the central processing unit of a computer.

  How to convert a string of binary into decimal

how to convert a string of binary into decimal and a decimal into binary using java

  How effective leader can manage changes for new technology

Write down separate 350-word document which explains how the effective leader can manage changes implementing this new technology might need.

  Determine the date in opening the letter from same file

if /home/jenny/draft and /home/Alex/letter are relates to same file and the following sequence of events occurs, determine the date in opening the letter?

  Determining z-transform and fourier transform

Consider the finite length sequencx(n)=D(n) + 0.5D (n-5). Determine z-transform and fourier transform of x(n). Determine N-point DFT of x(n) for N=50,10 and 5.

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