SlideShare a Scribd company logo
JAVA:
The mean of a list of numbers is its arithmetic average. The median of a list is its middle value
when the values are placed in order. For example, if a list contains 1, 4, 7, 8, and 10, then the
mean is 6 and the median is 7. Write an application that allows you to enter five integers and
displays the values, their mean, and their median.
Save the file as MeanMedian.java
RevisetheMeanMedianclasssothattheusercanenteranynumberofvaluesup to 20. If the list has an
even number of values, the median is the numeric average of the values in the two middle
positions.
Save the file as MeanMedian2.java
Solution
Source code:
import java.util.*;
class methods
{
public int sum (List a)
{
if (a.size() > 0)
{
int sum = 0;
for (Integer i : a)
{
sum += i;
}
return sum;
}
return 0;
}
public double mean (List a)
{
int sum = sum(a);
double mean = 0;
mean = sum / (a.size() * 1.0);
return mean;
}
public double median (List a)
{
int middle = a.size()/2;
if (a.size() % 2 == 1) {
return a.get(middle);
}
else {
return (a.get(middle-1) + a.get(middle)) / 2.0;
}
}
class t {
public static void main (String[]args)
{
methods m = new methods();
List c = Arrays.asList(1,4,7,8,10);
Collections.sort(c); System.out.println(m.median(c)); System.out.println(m.mean(c));
}
}

More Related Content

PDF
Javaa. The mean of a list of numbers is its arithmetic average. T.pdf
PPTX
Median (Central Value)
PPTX
Median
PPTX
Understanding Median in Mathematics: A Key Measure of Central Tendency
PPT
Measure of central tendency
PPT
Summary measures
PPT
Chapter 3 260110 044503
PPTX
Average & median
Javaa. The mean of a list of numbers is its arithmetic average. T.pdf
Median (Central Value)
Median
Understanding Median in Mathematics: A Key Measure of Central Tendency
Measure of central tendency
Summary measures
Chapter 3 260110 044503
Average & median

Similar to JAVAThe mean of a list of numbers is its arithmetic average. The .pdf (20)

PDF
Lecture 3 & 4 Measure of Central Tendency.pdf
PPTX
CORRELATION.pptx ,FOR ELECTIVE SUBJETCTS
PPTX
Mean Mode & Median
PPT
Measures of Central Tendancy
PPTX
MEASURE OF CENTRAL TENDENCY
PPTX
ED202-Median-final presentation for educational project
PPT
2 4 measures of center
PPTX
Median
PPT
Central Tendency
PPTX
Report in al1[1]
PPT
MEASURE OF CENTRAL TENDENCY TYPES OF AVERAGES Arithmetic mean Median Mode ...
PPT
Measures of Central Tendency Presentation.ppt
PPT
Measures of central Tendencies Mean_Median_Mode.ppt
PPT
Mean_Median_Mode Measures in Statistics.ppt
PPT
Mean_Median_Mode.ppt-rangeandset of data
PDF
I. central tendency
PPT
3 descritive statistics measure of central tendency variatio
PPTX
Statistics and probability lesson6&7
PPTX
STATISTCAL MEASUREMENTS.pptx
PPTX
Median
Lecture 3 & 4 Measure of Central Tendency.pdf
CORRELATION.pptx ,FOR ELECTIVE SUBJETCTS
Mean Mode & Median
Measures of Central Tendancy
MEASURE OF CENTRAL TENDENCY
ED202-Median-final presentation for educational project
2 4 measures of center
Median
Central Tendency
Report in al1[1]
MEASURE OF CENTRAL TENDENCY TYPES OF AVERAGES Arithmetic mean Median Mode ...
Measures of Central Tendency Presentation.ppt
Measures of central Tendencies Mean_Median_Mode.ppt
Mean_Median_Mode Measures in Statistics.ppt
Mean_Median_Mode.ppt-rangeandset of data
I. central tendency
3 descritive statistics measure of central tendency variatio
Statistics and probability lesson6&7
STATISTCAL MEASUREMENTS.pptx
Median
Ad

More from gopalk44 (20)

PDF
My protease appears to affect bacteria, but not my own cells. What t.pdf
PDF
Name the phases in interphase, and describe what happens during those.pdf
PDF
Look for at least four definitions of accounting (from four differen.pdf
PDF
Match the word or phrase with the best description of it. ;An express.pdf
PDF
Know and understand the contributions of Hooke, van Leeuwenhoek, Cohn.pdf
PDF
ImplementDijkstra’s algorithm using the graph class you implemente.pdf
PDF
Illegal numbers.a. Complete the method find which accepts a collec.pdf
PDF
how many chromosomes will be found in each cell at the end of anapha.pdf
PDF
how are the technological approaches of cloning and IPSCs similar to.pdf
PDF
HELP! Thought I can figure this one out but got it wrong. I have one.pdf
PDF
From a recent statistical analysis for the last five years, on an av.pdf
PDF
Find asymptotic upperlower bounds. Find asymptotic upperlower boun.pdf
PDF
Explain how a wireless device can help an organization perform busin.pdf
PDF
Exam scores were normal in BIO 200. Jasons exam score was one stan.pdf
PDF
Discuss the various types of business crimes, a business liability f.pdf
PDF
Describe the different types of ribs. Which ribs are considered “fal.pdf
PDF
Circle the best answer to the following questions. From the Bohr mod.pdf
PDF
C++ ProgramN-number queue rotations.[16] Write methods void Que.pdf
PDF
Below are two possible tree topologies. How many clades are different.pdf
PDF
WriteBelow are a list of descriptions that apply to either post s.pdf
My protease appears to affect bacteria, but not my own cells. What t.pdf
Name the phases in interphase, and describe what happens during those.pdf
Look for at least four definitions of accounting (from four differen.pdf
Match the word or phrase with the best description of it. ;An express.pdf
Know and understand the contributions of Hooke, van Leeuwenhoek, Cohn.pdf
ImplementDijkstra’s algorithm using the graph class you implemente.pdf
Illegal numbers.a. Complete the method find which accepts a collec.pdf
how many chromosomes will be found in each cell at the end of anapha.pdf
how are the technological approaches of cloning and IPSCs similar to.pdf
HELP! Thought I can figure this one out but got it wrong. I have one.pdf
From a recent statistical analysis for the last five years, on an av.pdf
Find asymptotic upperlower bounds. Find asymptotic upperlower boun.pdf
Explain how a wireless device can help an organization perform busin.pdf
Exam scores were normal in BIO 200. Jasons exam score was one stan.pdf
Discuss the various types of business crimes, a business liability f.pdf
Describe the different types of ribs. Which ribs are considered “fal.pdf
Circle the best answer to the following questions. From the Bohr mod.pdf
C++ ProgramN-number queue rotations.[16] Write methods void Que.pdf
Below are two possible tree topologies. How many clades are different.pdf
WriteBelow are a list of descriptions that apply to either post s.pdf
Ad

Recently uploaded (20)

PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PPTX
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
Hazard Identification & Risk Assessment .pdf
PDF
Practical Manual AGRO-233 Principles and Practices of Natural Farming
PDF
RMMM.pdf make it easy to upload and study
PPTX
History, Philosophy and sociology of education (1).pptx
PDF
SOIL: Factor, Horizon, Process, Classification, Degradation, Conservation
PPTX
Onco Emergencies - Spinal cord compression Superior vena cava syndrome Febr...
PDF
advance database management system book.pdf
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PPTX
Introduction to Building Materials
PDF
Trump Administration's workforce development strategy
PPTX
Digestion and Absorption of Carbohydrates, Proteina and Fats
DOC
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
PDF
A systematic review of self-coping strategies used by university students to ...
PDF
احياء السادس العلمي - الفصل الثالث (التكاثر) منهج متميزين/كلية بغداد/موهوبين
PDF
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
PPTX
Cell Types and Its function , kingdom of life
Chinmaya Tiranga quiz Grand Finale.pdf
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
Final Presentation General Medicine 03-08-2024.pptx
Hazard Identification & Risk Assessment .pdf
Practical Manual AGRO-233 Principles and Practices of Natural Farming
RMMM.pdf make it easy to upload and study
History, Philosophy and sociology of education (1).pptx
SOIL: Factor, Horizon, Process, Classification, Degradation, Conservation
Onco Emergencies - Spinal cord compression Superior vena cava syndrome Febr...
advance database management system book.pdf
202450812 BayCHI UCSC-SV 20250812 v17.pptx
Introduction to Building Materials
Trump Administration's workforce development strategy
Digestion and Absorption of Carbohydrates, Proteina and Fats
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
A systematic review of self-coping strategies used by university students to ...
احياء السادس العلمي - الفصل الثالث (التكاثر) منهج متميزين/كلية بغداد/موهوبين
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
Cell Types and Its function , kingdom of life

JAVAThe mean of a list of numbers is its arithmetic average. The .pdf

  • 1. JAVA: The mean of a list of numbers is its arithmetic average. The median of a list is its middle value when the values are placed in order. For example, if a list contains 1, 4, 7, 8, and 10, then the mean is 6 and the median is 7. Write an application that allows you to enter five integers and displays the values, their mean, and their median. Save the file as MeanMedian.java RevisetheMeanMedianclasssothattheusercanenteranynumberofvaluesup to 20. If the list has an even number of values, the median is the numeric average of the values in the two middle positions. Save the file as MeanMedian2.java Solution Source code: import java.util.*; class methods { public int sum (List a) { if (a.size() > 0) { int sum = 0; for (Integer i : a) { sum += i; } return sum; } return 0; } public double mean (List a) { int sum = sum(a); double mean = 0; mean = sum / (a.size() * 1.0);
  • 2. return mean; } public double median (List a) { int middle = a.size()/2; if (a.size() % 2 == 1) { return a.get(middle); } else { return (a.get(middle-1) + a.get(middle)) / 2.0; } } class t { public static void main (String[]args) { methods m = new methods(); List c = Arrays.asList(1,4,7,8,10); Collections.sort(c); System.out.println(m.median(c)); System.out.println(m.mean(c)); } }