Valisha
asked on
JAVA arrays and methods
I need help with fixing up the code that test the method in the main method.
And finding the index first occurance of the smallest index. My program finds the index of the smallest value in the entire array.
I am writing a program that takes the smallestindex that takes the parameters, a int array and it size and returns the index of the first ocuurene of the smallest value.
And finding the index first occurance of the smallest index. My program finds the index of the smallest value in the entire array.
I am writing a program that takes the smallestindex that takes the parameters, a int array and it size and returns the index of the first ocuurene of the smallest value.
{
double[] alpha = new double[50];
System.out.println(smallestindex(alpha));
{
public static int smallestIndex(int alpha[])
int index = 0;
int smallest;
smallest = data[0];
for(i =0; i < data.lenght(); i++)
if(smallest < data[i])
{
smallest = data[i];
index = i;
}
return index;
That's looking ok, apart from the array being empty as shown. What's the problem?
> for(i =0; i < data.lenght(); i++)
should be:
for(i =0; i < data.length; i++)
should be:
for(i =0; i < data.length; i++)
> double[] alpha = new double[50];
you also don't initialize your array
double[] alpha = new double[] { 1.2, 4.5, 1.7, 9.0, -3.4, 5.6};
or you could use a loop
you also don't initialize your array
double[] alpha = new double[] { 1.2, 4.5, 1.7, 9.0, -3.4, 5.6};
or you could use a loop
ASKER
System.out.println(smalles tindex(alp ha));
{
public static int smallestIndex(int alpha[])
is this part correct
{
public static int smallestIndex(int alpha[])
is this part correct
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.