Results 1 to 3 of 3
Thread: Maximum Minimum Values
- 05-09-2010, 12:22 AM #1
Member
- Join Date
- May 2010
- Posts
- 2
- Rep Power
- 0
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); } }
-
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!
- 05-09-2010, 12:36 AM #3
Member
- Join Date
- May 2010
- Posts
- 2
- Rep Power
- 0
Similar Threads
-
Calculating Maximum and Minimum
By Ejava in forum New To JavaReplies: 6Last Post: 03-01-2010, 04:36 PM -
minimum,/maximium
By sinista in forum New To JavaReplies: 7Last Post: 10-01-2009, 05:07 PM -
Help With Minimum Value
By Bodomar in forum New To JavaReplies: 1Last Post: 11-07-2008, 04:29 AM -
To find the Maximum and Minimum in an Array of Strings
By luscious in forum JavaServer Pages (JSP) and JSTLReplies: 9Last Post: 07-31-2008, 01:51 PM -
Minimum system requirements
By coco in forum New To JavaReplies: 1Last Post: 07-31-2007, 08:19 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks