Question: 4 . 5 People's weights ( Java ) ( 1 ) Prompt the user to enter five numbers, being five people's weights. Store the numbers
People's weights Java
Prompt the user to enter five numbers, being five people's weights. Store the numbers in an array of doubles. Output the array's numbers on one line, each number followed by one space. pts
Ex:
Enter weight :
Enter weight :
Enter weight :
Enter weight :
Enter weight :
You entered:
Also output the total weight, by summing the array's elements. pt
Also output the average of the array's elements. pt
Also output the max array element. pts
Ex:
Enter weight :
Enter weight :
Enter weight :
Enter weight :
Enter weight :
You entered:
Total weight:
Average weight:
Max weight: import java.util.Scanner;
public class PeopleWeights
public static void mainString args
Type your code here.
Scanner input new ScannerSystemin;
double weights new double;
int i ;
while i
System.out.printlnEnter weight i :;
weightsi input.nextDouble;
i;
outputWeightsweights;
System.out.printlntotalWeightweights;
System.out.printlnaverageWeightweights;
System.out.printlnmaxWeightweights;
public static void outputWeightsdouble arr
System.out.printYou entered: ;
for int i ; i arr.length; i
System.out.printarri;
System.out.println;
public static double totalWeightdouble arr
double sum ;
for int i ; i arr.length; i
sum sum arri;
return sum;
public static double averageWeightdouble arr
return totalWeightarr arr.length;
public static double maxWeightdouble arr
double temp arr;
for int i ; i arr.length; i
if arri temp
temp arri;
return temp;
Output differs. See highlights below.
Special character legend
Input
Your output starts with
Enter weight :
Enter weight :
Enter weight :
Enter weight :
Enter weight :
You entered:
Expected output starts with
Enter weight :
Enter weight :
Enter weight :
Enter weight :
Enter weight :
You entered:
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
