Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Computer Engineering Expert

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

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;

}

}

}

 

 

 

Computer Engineering, Engineering

  • Category:- Computer Engineering
  • Reference No.:- M9452993

Have any Question?


Related Questions in Computer Engineering

An oil company determines it costs 25000 to sink a test

An oil company determines it costs $25,000 to sink a test well, an oil hit yields a net revenue of $475,000($500,000 gross-$25,000costs), and a natural gas hit yields $125,000 net revenue ($150,000 gross-$25,000 costs). ...

Question you are in a social situation talking with

Question : You are in a social situation talking with coworkers, friends, or family members who are not familiar with the concept of networking, except for the idea that they turn on their computer and surf the World Wid ...

A summary of business activities of a course registration

A summary of business activities of a "Course Registration System" for enrolling courses for students and for enrolled class lists for faculty members at an online university is as follows: The Physics Department provide ...

Describe an ethical conundrum found in a magazine or

Describe an ethical conundrum found in a magazine or newspaper article, and please give your own thoughts. Give good citations, of course.

Reduce nfa to dfaconsider the transition table for nfa

Reduce NFA to DFA Consider the transition table for NFA N: 1.Draw a transition graph for machine N. Consider using JFLAP unless you have another tool you know for the problem. (I guess by hand will do, but that is so nin ...

Remember all of the following steps when showing that a

Remember all of the following steps when showing that a problem D is NPcomplete: 1. Show that D is in NP by briefly explaining how to quickly verify a solution to it. 2. Choose another problem Q that is known to be NP-ha ...

Xl cos dividends are expected to grow at a 20 rate for the

XL Co.'s dividends are expected to grow at a 20% rate for the next 3 years, with the growth rate falling off to a constant 6% thereafter. If the required return is 14% and the company just paid a $3.10 dividend, what is ...

There are sorted sequences l1 and l2 with 5 and 4 elements

There are sorted sequences L1 and L2, with 5 and 4 elements respectively. a) How many comparisons will it take to merge L1 and L2 in the best case? How many for worst case? Explain your answers. b) Let [54, 26, 93, 17, 7 ...

This is a chemistry question regarding physical and

This is a chemistry question regarding physical and chemical changes. The question is the following: You mix 3 liquids and the resulting solution becomes very hot. A short time later bubbles began to form. There is a che ...

Question suppose that the bcr stores only one bit value

Question : Suppose that the BCR stores only one bit value. Calculate the total number of memory bytes present in the system. Do not include the BCR register in the total.

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As