I need to figure out how to find the max number of an array by using a while loop. I have searched all over but do not understand how to do it. If I could get any help at all that would be great. Thanks!
Anyway the findMax method is the one that "is supposed to determine which number is the maximum of the array data.
// ReverseIntegers.java
// Nick Elliott 1/29/10
import java.io.*;
import java.util.Scanner;
public class ReverseIntegers
{
//interactively reads in a list of integers, one per line(max of 10)
// and prints out the list in reverse order
public static void main(String [] args)throws IOException
{
Integer [] data = new Integer[10];
System.out.println("Type in a list of integers, one per line." + "\nPress enter at a blank line to stop");
int size = readData(data);
int max = findMax(data,size);
System.out.println("The largest integer in your data is " + max);
System.out.println("\nYour data reversed: ");
printDataReversed(data,size);
}
// interactively reads a list of integers into data array
// returns number of integers stored
public static int readData(Integer[]data) throws IOException
{
Scanner scanner = new Scanner(System.in);
String line = null;
int count=0;
while( true )
{
line = scanner.nextLine();
if(line.equals(""))
break;
data[count] = new Integer(line);
count++;
}
return count; //number of data elements stored
}
//print data[0..size-1] in reverse order
public static void printDataReversed(Integer[] data, int size)
{
int count=size-1;
while(count>=0)
{
System.out.println(data[count]);
count--;
}
}
//Finds the max number in the aray and prints it
public static int findMax(Integer[] data, int size)
{
//No idea???
System.out.println("The maximum integer is : ");
}
}
Thank you for your time :)