Hi I'm really struggling with this homework assignment, I'd appreciate it if you helped me out!
this is the instruction:
Create a program called BiggestElement that will allow the user to input five integers. The program will then output the largest of the five numbers.*Include a function-type method that will return to the main method the value of the largest element in the array.*Use the length method to help determine the number of elements in the array.
My problem is that when I run the program it states the first input as the biggest element instead of the biggest number. I think its something wrong with my bubble sorting but I'm not sure.
this is my code:
**import java.io.*;
public class BiggestElement
{
public static void main (String[] args) throws IOException
{
double favNums[] = new double [6];
populate (favNums);
System.out.println ("The largest value is " + findBiggest (favNums));
} // main method
public static void populate (double favNums[]) throws IOException
{
DataInputStream input = new DataInputStream (System.in);
for (int x = 0 ; x < 5 ; x++)
{
System.out.print ("Enter any number: ");
favNums [x] = Double.parseDouble (input.readLine ());
}
} //populate class
public static double findBiggest (double favNums[])
{
double biggest = favNums [0];
double hold;
for (int x = 1 ; x < 5 ; x++)
{
if (favNums [x] > favNums[x + 1])
{
hold = favNums [x];
favNums [x] = favNums [x + 1];
favNums [x + 1] = hold;
}
}
return biggest;
} //findBiggest class
} // BiggestElement class**