I haven't posted since I finished my C++ class. Now on to Java. Seems a bit easier...
Well here is my problem. I am trying to use the max and min method to determine the max and min number enterd by the user into an array. I could type out all the code to make a class, but want to keep it simple. The errors I get are:
FindAverage.java:31: cannot find symbol
symbol : method max(int)
location: class java.lang.Math
int maxNums = Math.max(0, Math.max( array[counter]));
^
FindAverage.java:32: cannot find symbol
symbol : method min(int)
location: class java.lang.Math
int minNums = Math.min(0, Math.min( array[counter]));
^
2 errors
Here is the code: any help is appreciated.
import javax.swing.JOptionPane;
public class FindAverage
/* Main method */
{
public static void main(String args[])
{
String strPrompt = "Enter integer values, enter 0 to mark end of file:";
int[] array = new int[10];//Amount entered from keyboard
int nums = 0;
int sum = 0;
int counter = 0;
float avg = 0;
//Receive amount entered from keyboard
do
{
String strData = JOptionPane.showInputDialog(strPrompt);
nums = Integer.parseInt(strData);
array[counter] = nums;
sum += nums;
counter++;
}
while (nums != 0);
counter -= 1;
avg = sum / counter;
int maxNums = Math.max(0, Math.max( array[counter]));
int minNums = Math.min(0, Math.min( array[counter]));
JOptionPane.showMessageDialog(null,
"You entered " + counter + " numbers:\n" +
" The sum is: " + sum +
"\n The avg is: " + avg +
"\n The largest value is: " + maxNums +
"\n The smallest value is: " + minNums );
}
}

New Topic/Question
Reply



MultiQuote








|