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
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 now
This is a popular solution!
Step by step
Solved in 3 steps with 2 images