Results 1 to 3 of 3
  1. #1
    Join Date
    May 2010
    Posts
    2
    Rep Power
    0

    Default Maximum Minimum Values

    I'm working on some code and the book I have is being of no real help as well as in the internet since most people use finding max/min in arrays but I need to use it from data entered by the user.
    PHP Code:
    import javax.swing.JOptionPane;
    public class exam
    {
    	public static void main(String [] args)
    	{
    		String inputString;
    		int testnum=1;
    		int testScore;
    		double average;
    		int max;
    		int min;
    		do
    		{
    			inputString=JOptionPane.showInputDialog("Please enter your test score.");
    				testScore=Integer.parseInt(inputString);
    			testnum++;
    		}while(testnum<=10);
    		average=(testScore+testScore+testScore+testScore+testScore+testScore+testScore+testScore+testScore+testScore)/10;
    		JOptionPane.showMessageDialog(null,"The lowest score is " + min(testScore));
    		JOptionPane.showMessageDialog(null, "The highest score is " +max(testScore));
    		JOptionPane.showMessageDialog(null, "The average score is " + average);
    
    		System.exit(0);
    	}
    }

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    You'll find the min and max similar to how you'd manually do it with an array: have a min var that you'll compare the input to and if input is less, set = to input, and similarly for max (though you'll be checking if input value is greater than max of course). Also, you'll want a total value that you add as the values are input. Your testScore + testScore + .... will only add the last entered value ten times.

    Keep on working at it. Much luck!

  3. #3
    Join Date
    May 2010
    Posts
    2
    Rep Power
    0

    Default

    Crud, I didn't even see the error with finding the average. If I were to add another 9 lines and change testScore to testScore1 and so on. Would that work?

Similar Threads

  1. Calculating Maximum and Minimum
    By Ejava in forum New To Java
    Replies: 6
    Last Post: 03-01-2010, 05:36 PM
  2. minimum,/maximium
    By sinista in forum New To Java
    Replies: 7
    Last Post: 10-01-2009, 06:07 PM
  3. Help With Minimum Value
    By Bodomar in forum New To Java
    Replies: 1
    Last Post: 11-07-2008, 05:29 AM
  4. To find the Maximum and Minimum in an Array of Strings
    By luscious in forum JavaServer Pages (JSP) and JSTL
    Replies: 9
    Last Post: 07-31-2008, 02:51 PM
  5. Minimum system requirements
    By coco in forum New To Java
    Replies: 1
    Last Post: 07-31-2007, 09:19 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •