I need help with my spacing for my code. I attached what my code is expected to look like but i guess there is a spacing error. i need to match the expected output
heres my code
import java.util.Scanner;
public class PeopleWeights {
public static void main(String[] args) {
//object of Scanner class to read input from keyboard
Scanner kboard=new Scanner(System.in);
final int SIZE=5;
double total=0;
double average=0;
double max=0;
//create an array of size,5
double[] weights=new double[SIZE];
//Read five double values
for (int i = 0; i < weights.length; i++) {
System.out.printf("Enter weight %d : ", i+1);
weights[i]=Double.parseDouble(kboard.nextLine());
total=total+weights[i];
}//end of for loop
System.out.print("You entered: ");
for (int i = 0; i < weights.length; i++) {
System.out.printf("%.1f ", weights[i]);
}
//print the total weight value
System.out.printf("\nTotal weight: %.1f\n",total);
//calcualte average of weights
average=total/SIZE;
System.out.println("Average weight: "+average);
//Assume first element in weights array is maximum
max=weights[0];
for (int i = 0; i < weights.length; i++) {
if(weights[i]>max)
max=weights[i];
}
//print max element
System.out.printf("Max weight: %.1f\n",max);
}//end of the main method
}//end of the class
Trending nowThis is a popular solution!
Step by stepSolved in 3 steps with 2 images
- Help writing a Java program (please provide photos it works so I'm not studying a nonworking program) Write a complete version of the Bresenham Midpoint algorithm to handle ALL slope values. Include appropriate tests for ‘special case’ conditions. Instead of “WritePixel” write to the screen the coordinates of the pixel that would be drawn. Your program must implement the algorithm given in class with modifications to handle the special cases. Different slope values: m = 0, m = 1, m = > 1, m = infinity (needs special test case) , m < 0 (swap x and y) The user should be able to enter coordinates and it should output the coordinates it takes to draw from the first point to the last pointarrow_forwardUpload answer sheets Compare the effectiveness of input statements putchar(), fgets() and gets() when working with character arrays. Discuss the concepts with an examplearrow_forwardUse Java language and the last digit of ID is a 7arrow_forward
- MAKE SURE THAT THE SCRIPT TAKES DECIMALS VALUES ALSO AS INPUTarrow_forward- Write a java program that contains a two-dimensional array of 2 rows and 3 columns. Find the sum of each row in the array, trace the code using a tracing table. - Note: No two students can try the same inputs. - You should submit the code and the tracing table in a handwritten pdf file. - Also, you should submit the code and a screenshot of the output using a word file. Tracing Table may look like the following table: Line# i j Array[0][0] Array[0][1] Array[0][2] Array[1][0] Array[1][1] Array[1][2] rowSum Output …….arrow_forward
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY