Question: Enter weight 1 : Enter weight 2 : Enter weight 3 : Enter weight 4 : Enter weight 5 : You entered: 2 3 6

Enter weight 1:
Enter weight 2:
Enter weight 3:
Enter weight 4:
Enter weight 5:
You entered: 236.089.5142.0166.393.0 See illustration input correct space. Fix following syntax: import java.util.Scanner;
public class PeopleWeights {
public static void main(String[] args){
Scanner scnr = new Scanner(System.in);
// Array to store weights
double[] weights = new double[5];
// Prompt user for weights
for (int i =0; i weights.length; i++){
System.out.print("Enter weight "+(i +1)+":
");
weights[i]= scnr.nextDouble();
}
// Display entered weights
System.out.print("You entered: ");
for (int i =0; i weights.length; i++){
System.out.print(weights[i]);
if (i weights.length -1){
System.out.print("");
}
}
System.out.print(""); // Add space after the final output
System.out.println(); // Move to the next line for proper formatting
scnr.close();
}
}
Enter weight 1 : Enter weight 2 : Enter weight 3

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!