Posted: Wed Nov 17, 2004 5:42 pm Post subject: Finding the mode and median if the given numbers I have 10 input numbers, now i know how to calculate the mean and maximum and minimum but i am stuck with how to calculate the mode. First Program finds the average of specified array elements. The second programs takes the value of n (number of elements) and the numbers provided by user and finds the average of them using array. To understand these programs you should have the knowledge of following Java Programming concepts: 1) Java Arrays 2) For loop.
- How To Calculate The Median
- Java Program To Calculate Mean Median Models
- Mean Median Mode Calculators
- Java Program To Calculate Mean Median Mode And Range
Greenhorn
posted 16 years agook heres the thing i am trying to create a program (in java of course) that will find the mode of ten seperately inputted numbers, no arrays, i hate them and i know theres plent of ways to get around them, anywho im not having any luck, help me please
Ranch Hand
posted 16 years ago
Sheriff
posted 16 years agoDefintion of 'mode' --> The mode of a set of data is the value in the set that occurs most often.
Chase-
So, you're trying to calculate the mode of a set of data, and you don't want to use an array. What have you tried? Where are you having trouble? What part are you not able to 'get'? We'd love to help you, but we're not going to do the work for you. If you'd like to post your code and specifically explain what the problem is -- we'd be more than happy to help you de-bug the problem and maybe even offer some alternative solutions. How's that sound?
In the mean time, Im moving this to Java In General (Beginner) forum, where I think its more appropriate. Good luck!
Chase-
So, you're trying to calculate the mode of a set of data, and you don't want to use an array. What have you tried? Where are you having trouble? What part are you not able to 'get'? We'd love to help you, but we're not going to do the work for you. If you'd like to post your code and specifically explain what the problem is -- we'd be more than happy to help you de-bug the problem and maybe even offer some alternative solutions. How's that sound?
In the mean time, Im moving this to Java In General (Beginner) forum, where I think its more appropriate. Good luck!
- Jess
Blog:KnitClimbJava | Twitter: jsant | Ravelry: wingedsheep
Blog:KnitClimbJava | Twitter: jsant | Ravelry: wingedsheep
(instanceof Sidekick)
posted 16 years agoTry to think up a solution in relatively plain english. Maybe
Now you have a handful of small problems:
How do you go through your input set?
How do you keep a counter for each number?
Where do you remember the highest counter so far?
Where do you remember the number that got the highest count?
And if you really want to blow your instructor away, show em this: http://www.cs.utexas.edu/users/moore/best-ideas/mjrty/index.html (Shucks, that only works if there is a MAJORITY number, I think)
Have fun! Don't take my word for that plain language algorithm. See if you can do better!
Now you have a handful of small problems:
How do you go through your input set?
How do you keep a counter for each number?
Where do you remember the highest counter so far?
Where do you remember the number that got the highest count?
And if you really want to blow your instructor away, show em this: http://www.cs.utexas.edu/users/moore/best-ideas/mjrty/index.html (Shucks, that only works if there is a MAJORITY number, I think)
Have fun! Don't take my word for that plain language algorithm. See if you can do better!
Hoyle board games 2013 free full version. A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Greenhorn
posted 16 years agook there is nothing wrong with the code, but i just have no clue of the formula i am sposed to actually use, that is my only problem, and if you cant help that is fine
Greenhorn
posted 16 years agoim sitting right next to him and here is the problem that he is having he needs to write a program to calculate the code he has the code wrote out he just needs help figuring out the math like should he use a switch statement but the only problem is the user can enter any range of numbers
lowercase baba
posted 16 years agoWhat code do you have written out? What does it do/not do? What part are you having trouble with exactly?
People here love to help, but i'm not sure what your problem is. just telling us 'it doesn't work' doesn't do any good. If the code isn't too long, you can use the code tags and post what you written so far, and someone will probably give you some suggestions.
People here love to help, but i'm not sure what your problem is. just telling us 'it doesn't work' doesn't do any good. If the code isn't too long, you can use the code tags and post what you written so far, and someone will probably give you some suggestions.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Greenhorn
posted 16 years agook he has the input wrote out and what he is having problems with is the math cause he doesnt really know what to do like what system he should use or what so is there anyone that can help him figure out the math part of the program of like what he should do cause the user can enter any number
lowercase baba
posted 16 years agoi don't know what you mean by 'what system should he use'.
there really isn't a lot of math involved in figuring out the mode. you need to scan all the input values, and count how many times each unique value appears. for example, if the 10 input numbers are:
5,8,2,3,6,5,1,8,0,8
since 8 occurs more than any other number, the mode is 8. the only math involved is simple addition and doing some comparisons (i.e. is one value greater than another).
when you say 'he has the input wrote', is he saving all 10 input numbers, so they can all be accessed later? or is he incrementing a counter for each as it is input?
again, it's much easier to help if you POST THE CODE. there are probably hundreds of ways to do this, but without knowing what path you've started, everybody is just making blind guesses on how to help you get further along.
[ May 11, 2004: Message edited by: fred rosenberger ]
there really isn't a lot of math involved in figuring out the mode. you need to scan all the input values, and count how many times each unique value appears. for example, if the 10 input numbers are:
5,8,2,3,6,5,1,8,0,8
since 8 occurs more than any other number, the mode is 8. the only math involved is simple addition and doing some comparisons (i.e. is one value greater than another).
when you say 'he has the input wrote', is he saving all 10 input numbers, so they can all be accessed later? or is he incrementing a counter for each as it is input?
again, it's much easier to help if you POST THE CODE. there are probably hundreds of ways to do this, but without knowing what path you've started, everybody is just making blind guesses on how to help you get further along.
[ May 11, 2004: Message edited by: fred rosenberger ]
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Ranch Hand
posted 16 years agoStan James has already posted pseudocode for the algorithm you can use. Now all you need to do is change it into Java code.
If you still don't understand, please post the code you already have and what problems you've encountered in trying to implement the code. You should also try writing out an explanation, in your native language, of the steps you should take to find the answer. Perhaps it will help to do an example by hand. Then you can more easily see what steps are needed.
HTH
Layne
If you still don't understand, please post the code you already have and what problems you've encountered in trying to implement the code. You should also try writing out an explanation, in your native language, of the steps you should take to find the answer. Perhaps it will help to do an example by hand. Then you can more easily see what steps are needed.
HTH
Layne
Calculating the mean, median, and mode in Oracle SQL is a task often performed by report developers or anyone else working with SQL. Learn how to calculate these three values from a range of data in this article.
![Mode Mode](https://javatutoring.com/wp-content/uploads/2016/11/average-of-numbers-java-program.gif)
What is the Mean, Median, and Mode, and Standard Deviation?
Mean, median, and mode are three kinds of average values that can be obtained from a set of data.
You might have learnt about them in high school maths (like I did) but may have forgotten what they are (like I did).
- Mean: This is the “average” that you might know. It’s the sum of all of the numbers divided by the count of numbers.
- Median: This is the middle value of a list of numbers.
- Mode: This is the value that occurs most often
- Standard Deviation: A value that represents how much numbers differ from each other
How Can I Calculate the Mean in Oracle SQL?
Let’s say we had a table of data called movie_ratings that looked like this:
RATING |
11 |
12 |
15 |
19 |
12 |
13 |
16 |
20 |
How could we find the mean of these values?
We can use the AVG function.
Result:
MEAN_RATING |
14.75 |
You can see the average is 14.75. This is because we added all of the numbers up (which equals 118) and then divided by the count of numbers (which is 8). 118/8 = 14.75.
How Can I Calculate the Median in Oracle SQL?
To calculate the median in Oracle SQL, we use the MEDIAN function.
The MEDIAN function returns the median of the set of provided values.
The MEDIAN is the middle value in a set of values.
So, for example, you had these five values:
10, 15, 18, 23, 40.
The median of these would be the middle value after they have been ordered in ascending order. So, the median would be 18.
Median Function Parameters
The MEDIAN function can be used as either an analytic function or an aggregate function.
The parameters of the MEDIAN function are:
- expr (mandatory): The expression to calculate a median for. This can be a set of numbers, or a column.
- query_partition_clause (optional): The clause that is used to partition the data when using MEDIAN as an analytic query.
The expr value can be any numeric data type. The MEDIAN function returns the same data type as the expr value.
If you specify the OVER clause, Oracle will work out the data type with the highest precedence and return that type.
Finding the Median
The MEDIAN function looks like this:
Result:
MEDIAN_RATING |
14 |
You can see that the median is 14. This is because the middle value would be 14.
While there are 8 values and there is no middle value, the median is calculated as the point between the two middle values.
So, if we order the values they would be:
11, 12, 12, 13, 15, 16, 19, 20
The middle two values are 13 and 15, and the mid point between them is 14.
How Can I Calculate the Mode in Oracle SQL?
To calculate the mode, we need to use the STATS_MODE function.
Result:
MODE_RATING |
12 |
The mode is 12 as that is the most occurring value in the table.
Show the Mean, Median and Mode All In One Query
Let’s use these examples to show the mean, median, and mode all in the same query.
Result:
MEAN_RATING | MEDIAN_RATING | MODE_RATING |
14.75 | 14 | 12 |
As you can see, the values here are the same as the earlier examples.
So, that’s how you find the mean, median, and mode in Oracle SQL.
Examples of the MEDIAN Function
Here are some further examples of the MEDIAN function. I find that examples are the best way for me to learn about code, even with the explanation above.
Example 1 – aggregate
This example finds the median using it as an aggregate function.
Result:
MEDIAN_FEES_REQ |
300 |
It shows the value of 300 because this is the middle value in the column after it has been ordered.
Example 2 – analytic
This example uses the MEDIAN function as an analytic function
Result:
FIRST_NAME | LAST_NAME | ADDRESS_STATE | FEES_REQUIRED | MEDIAN_FEES_REQ |
Mark | Anderson | California | 860 | 860 |
Robert | Pickering | Colorado | 110 | 130 |
Susan | Johnson | Colorado | 150 | 130 |
Michelle | Randall | Florida | 250 | 250 |
John | Rogers | Nevada | 210 | 280 |
Tom | Capper | Nevada | 350 | 280 |
Steven | Webber | New York | 100 | 500 |
Mark | Holloway | New York | 500 | 500 |
John | Smith | New York | 500 | 500 |
Mary | Taylor | Oregon | 500 | 500 |
Julie | Armstrong | Texas | 100 | 150 |
Tanya | Hall | Texas | 150 | 150 |
Andrew | Cooper | Texas | 800 | 150 |
Jarrad | Winston | Utah | 700 | 700 |
This example shows the median fees_required when grouped by the home_state for each record in the table.
How to Find the Standard Deviation in Oracle
Another statistic you may want to find is the standard deviation.
This can be achieved with the STDDEV function.
The purpose of the STDDEV function is to find the standard deviation of a set of numbers.
The standard deviation is a mathematical concept, which is a number that represents how much the values in a group differ from the mean value in a group.
This function can be used as either an analytical function or an aggregate function.
Oracle STDDEV Function Syntax and Parameters
The syntax for the STDDEV function when it is used as an aggregate function is:
STDDEV ( [DISTINCT | ALL] expression )
How To Calculate The Median
Alternatively, the syntax when used as an analytical function is:
STDDEV ( [DISTINCT | ALL] expression ) [OVER (analytical_clause) ]
The parameters of the STDDEV function as an aggregate function are:
- DISTINCT|ALL (optional): Using DISTINCT means that the function will only look at unique values. Using ALL means that all values will be considered.
- expression (mandatory): The expression is the set of data or the column that is used in the STDDEV function.
The parameters of the STDDEV function as an analytical function are the same, but also include:
- analytical_clause (optional): This is the clause or logic that is used to group the values for the STDDEV function.
Examples of the STDDEV Function
Here are some examples of the STDDEV function. I find that examples are the best way for me to learn about code, even with the explanation above.
Example 1
This example uses the STDDEV funiotn as an aggregate function.
Result:
STDDEV(FEES_REQUIRED) |
234.7788558 |
Example 2
This example uses the STDDEV function as an aggregate function again, but I’ve used the DISTINCT keyword.
Result:
STDDEV(DISTINCTFEES_REQUIRED) |
254.9322973 |
Example 3
This example uses the STDDEV function as an analytical function.
Java Program To Calculate Mean Median Models
Result:
ENROLMENT_DATE | ENROLMENT_MTH | STDEV_VAL |
01/Feb/15 | FEB | 282.8427125 |
12/Feb/15 | FEB | 282.8427125 |
30/Jan/15 | JAN | 176.5812911 |
12/Jan/15 | JAN | 176.5812911 |
20/Jan/15 | JAN | 176.5812911 |
28/Jan/15 | JAN | 176.5812911 |
23/Jan/15 | JAN | 176.5812911 |
04/Mar/15 | MAR | 234.7788558 |
06/Mar/15 | MAR | 234.7788558 |
09/Mar/15 | MAR | 234.7788558 |
You can see that for each of the enrolment_mth values that are the same, the stdev_val is the same.
Mean Median Mode Calculators
So, that’s how you find the mean, median, mode, and standard deviation in Oracle SQL.
Java Program To Calculate Mean Median Mode And Range
Lastly, if you enjoy the information and career advice I’ve been providing, sign up to my newsletter below to stay up-to-date on my articles. You’ll also receive a fantastic bonus. Thanks!