SlideShare a Scribd company logo
1 of 2
Download to read offline
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

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

Step 1You need to run the JAVA programs in sections 3.3 and 3.5 for.pdf
Step 1You need to run the JAVA programs in sections 3.3 and 3.5 for.pdfStep 1You need to run the JAVA programs in sections 3.3 and 3.5 for.pdf
Step 1You need to run the JAVA programs in sections 3.3 and 3.5 for.pdfaloeplusint
 
Data structure.pptx
Data structure.pptxData structure.pptx
Data structure.pptxSajalFayyaz
 
pandas-221217084954-937bb582.pdf
pandas-221217084954-937bb582.pdfpandas-221217084954-937bb582.pdf
pandas-221217084954-937bb582.pdfscorsam1
 
Java AssignmentUsing the ListNode.java file below Write method.pdf
Java AssignmentUsing the ListNode.java file below Write method.pdfJava AssignmentUsing the ListNode.java file below Write method.pdf
Java AssignmentUsing the ListNode.java file below Write method.pdfambersushil
 
Write a method expand that could be added to the LinkedlntList class f.docx
Write a method expand that could be added to the LinkedlntList class f.docxWrite a method expand that could be added to the LinkedlntList class f.docx
Write a method expand that could be added to the LinkedlntList class f.docxnoreendchesterton753
 
Write a method expand that could be added to the LinkedlntList class .docx
 Write a method expand that could be added to the LinkedlntList class .docx Write a method expand that could be added to the LinkedlntList class .docx
Write a method expand that could be added to the LinkedlntList class .docxajoy21
 
Microsoft® Excel® 2016ExploringSeries Editor Mary Anne Poats.docx
Microsoft® Excel® 2016ExploringSeries Editor Mary Anne Poats.docxMicrosoft® Excel® 2016ExploringSeries Editor Mary Anne Poats.docx
Microsoft® Excel® 2016ExploringSeries Editor Mary Anne Poats.docxARIV4
 
9781439035665 ppt ch09
9781439035665 ppt ch099781439035665 ppt ch09
9781439035665 ppt ch09Terry Yoast
 
9781111530532 ppt ch09
9781111530532 ppt ch099781111530532 ppt ch09
9781111530532 ppt ch09Terry Yoast
 

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

Cliff tip indexmatch_01
Cliff tip indexmatch_01Cliff tip indexmatch_01
Cliff tip indexmatch_01
 
Step 1You need to run the JAVA programs in sections 3.3 and 3.5 for.pdf
Step 1You need to run the JAVA programs in sections 3.3 and 3.5 for.pdfStep 1You need to run the JAVA programs in sections 3.3 and 3.5 for.pdf
Step 1You need to run the JAVA programs in sections 3.3 and 3.5 for.pdf
 
12. arrays
12. arrays12. arrays
12. arrays
 
java_lect_03-2.ppt
java_lect_03-2.pptjava_lect_03-2.ppt
java_lect_03-2.ppt
 
OOPs with java
OOPs with javaOOPs with java
OOPs with java
 
Chap09
Chap09Chap09
Chap09
 
Generics collections
Generics collectionsGenerics collections
Generics collections
 
Arrays
ArraysArrays
Arrays
 
Data structure.pptx
Data structure.pptxData structure.pptx
Data structure.pptx
 
Pandas.pptx
Pandas.pptxPandas.pptx
Pandas.pptx
 
pandas-221217084954-937bb582.pdf
pandas-221217084954-937bb582.pdfpandas-221217084954-937bb582.pdf
pandas-221217084954-937bb582.pdf
 
Java AssignmentUsing the ListNode.java file below Write method.pdf
Java AssignmentUsing the ListNode.java file below Write method.pdfJava AssignmentUsing the ListNode.java file below Write method.pdf
Java AssignmentUsing the ListNode.java file below Write method.pdf
 
Python.pptx
Python.pptxPython.pptx
Python.pptx
 
Write a method expand that could be added to the LinkedlntList class f.docx
Write a method expand that could be added to the LinkedlntList class f.docxWrite a method expand that could be added to the LinkedlntList class f.docx
Write a method expand that could be added to the LinkedlntList class f.docx
 
Write a method expand that could be added to the LinkedlntList class .docx
 Write a method expand that could be added to the LinkedlntList class .docx Write a method expand that could be added to the LinkedlntList class .docx
Write a method expand that could be added to the LinkedlntList class .docx
 
Microsoft® Excel® 2016ExploringSeries Editor Mary Anne Poats.docx
Microsoft® Excel® 2016ExploringSeries Editor Mary Anne Poats.docxMicrosoft® Excel® 2016ExploringSeries Editor Mary Anne Poats.docx
Microsoft® Excel® 2016ExploringSeries Editor Mary Anne Poats.docx
 
Data structures in c#
Data structures in c#Data structures in c#
Data structures in c#
 
13 arrays
13 arrays13 arrays
13 arrays
 
9781439035665 ppt ch09
9781439035665 ppt ch099781439035665 ppt ch09
9781439035665 ppt ch09
 
9781111530532 ppt ch09
9781111530532 ppt ch099781111530532 ppt ch09
9781111530532 ppt ch09
 

More from gopalk44

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

More from gopalk44 (20)

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

Recently uploaded

Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 
Third Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxThird Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxAmita Gupta
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxnegromaestrong
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docxPoojaSen20
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin ClassesCeline George
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701bronxfugly43
 

Recently uploaded (20)

Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Third Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxThird Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptx
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 

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)); } }