
a.
Explanation of Solution
Program:
File name: “MeanMedian.java”
//Import necessary header files
import javax.swing.*;
//Define a class named MeanMedian
class MeanMedian
{
//Define a main method
public static void main(String[] args)
{
//Declare an array of nine integers
int[] nums = new int[9];
//Declare the variables and initialize the values
String entry;
String list = "You entered: ";
int a, b;
int temp;
int midPos;
int total = 0;
double mean;
//For loop to be executed until a exceeds 9
for(a = 0; a < nums.length; ++a)
{
//Prompt the user to enter a number
entry = JOptionPane.showInputDialog(null,
"Enter number " + (a + 1));
nums[a] = Integer.parseInt(entry);
//Compute the total
total += nums[a];
//If a equals zero
if(a == 0)
//Find the list
list += nums[a];
//Else a not equals zero
else
//Find the list
list += ", " + nums[a];
}
//Print the result
System...
b.
Explanation of Solution
Program:
File name: “MeanMedian2.java”
//Import necessary header files
import javax.swing.*;
//Define a class named MeanMedian2
class MeanMedian2
{
//Define a main method
public static void main(String[] args)
{
//Declare an array of 20 integers
int[] nums = new int[20];
//Declare the variables and initialize the values
int num = 0;
String entry;
String list = "You entered: ";
int a, b;
int temp;
double median;
int total = 0;
double mean = 0;
final int QUIT = 9999;
int size = 0;
/*For loop to be executed until a exceeds 20 and does not enter QUIT*/
for(a = 0; num != QUIT && a < nums.length; ++a)
{
//Prompt the user to enter a number or QUIT
entry = JOptionPane.showInputDialog(null,
"Enter number " + (a + 1) + " or " + QUIT + " to quit");
num = Integer.parseInt(entry);
//If the user does not enter QUIT
if(num != QUIT)
{
//Assign the value
nums[a] = num;
//Find the total
total += nums[a];
//If a equals zero
if(a == 0)
//Find the list
list += nums[a];
//Else
else
//Find the list
list += ", " + nums[a];
}
}
//Print the result
System.out.println("size is " + a);
//If the user does not enter QUIT
if(num != QUIT)
//Find the size
size = nums...

Trending nowThis is a popular solution!

Chapter 9 Solutions
Java Programming (MindTap Course List)
- Design and draw a high-level "as-is" process diagram that illustrates a current process related to a product or service offered through the SSDCI.gov database.arrow_forwardCompare last-mile connections for connecting homes and businesses to the Internetarrow_forwardExplain wireless networking standardsarrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTEBK JAVA PROGRAMMINGComputer ScienceISBN:9781305480537Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,
- Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageProgramming with Microsoft Visual Basic 2017Computer ScienceISBN:9781337102124Author:Diane ZakPublisher:Cengage Learning



