# BigElement-HELP

• 03-05-2009, 06:16 PM
bobmasta5
BigElement-HELP
Assignment number 2:
Create a program called BigElement 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 (Hint: the flowchart below shows the algorithm that could be used for the method). Use the length method to help determine the number of elements in the array.

This is assignment 2 that I need to complete quickly and all I have is this:
// The "BiggestElement" class.
import java.awt.*;
import hsa.Console;

public class BiggestElement
{
static Console c; // The output console

public static void main (String[] args)
{
c = new Console ();
int biggest[] = new int [5];
//i know this part is wrong, im not sure what to do exactly
c.println ("Please input five integers: ");

} // main method
} // BiggestElement class
• 03-05-2009, 08:01 PM
bigbigbug
if you have 5 elements, make a "for" loop, initialize a int variable max=0
in each time, you compare max with each element, if max is smaller, than assign max as that element,
hope it helps
• 03-06-2009, 03:16 AM
bobmasta5
Sorry not quite sure I got it....would you happen to have msn so I can ask a few questions quicker? ...I aprreciate the help.
c = new Console ();
int biggest[] = new int [5];
c.println ("Please input five integers: ");
for (int max = 0 ; max < biggest ; max++)
{

}
} // main method
• 03-06-2009, 03:49 AM
CJSLMAN
pseudo code
It would llook something like this:

Code:

```create array of 5 elements start loop ask user for int assign int to array end loop call method (sortMethod?) with array as a parameter print the int retunred from the method begining of sort method do sort stuff return the biggest element (int) end method```
Luck,
CJSL
• 03-06-2009, 05:47 PM
bobmasta5
Ok so this is what I have now, im not sure if my loop in the sortMethod is correct, also i get an error when i try to print the method out from the main method

Code:

```public static void main (String[] args)     {         c = new Console ();         //create array of 5 elements         int fiveNumber[] = new int [5];         int max = 0;         //ask the user for five integers         c.println ("Please input five integers: ");         //start a loop so that the user can enter five integers         for (int i = 0 ; i < 5 ; i++)         {             fiveNumber [i] = c.readInt ();         }         c.println ("The largest number entered was " + sortMethod (max));     } // main method     public static int sortMethod (int fiveNumber, int max)     {         for (int i = 0 ; i < 5 ; i++)         {             if (fiveNumber > max)                 max = fiveNumber;         }         return max;     }```
• 03-06-2009, 06:18 PM
bobmasta5
nevermind i got the program to run!:
Code:

```c = new Console ();         //create array of 5 elements         int fiveNumber[] = new int [5];         //declare a variable to determine the largest number         int max = 0;         //ask the user for five integers         c.println ("Please input five integers: ");         //start a loop so that the user can enter five integers         for (int i = 0 ; i < 5 ; i++)         {             fiveNumber [i] = c.readInt ();         }         //print the largest number, that has been returned from the sortMethod method         c.println ("The largest number entered was " + sortMethod (fiveNumber, max));     } // main method     //create a new method called SorthMethod to determine which of the five numbers is the largest     public static int sortMethod (int[] fiveNumber, int max)     {         //use a loop to determine out of five numbers which is the largest         for (int i = 0 ; i < 5 ; i++)         {             if (fiveNumber [i] > max)                 max = fiveNumber [i];         }         //return the max integer, which is now the largest integer in the given array         return max;     }```
• 03-06-2009, 07:05 PM
CJSLMAN
`public static int sortMethod (int[] fiveNumber, [B][COLOR="Red"]int max[/COLOR][/B])`