Question
Question? Can anyone tell me how to fix Space: An unexpected space was detected in the output. Here is my code: import java.util.Scanner; public class
Question?
Can anyone tell me how to fix
Space: An unexpected space was detected in the output.
Here is my code:
import java.util.Scanner;
public class WeightAnalysis {
final static int NUM_WEIGHTS = 5;
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
double a[] = new double[NUM_WEIGHTS];
for(int i=0;i System.out.println("Enter weight "+(i+1)+":"); a[i] = keyboard.nextDouble(); } System.out.println(); double sumWeight = 0,avgWeight = 0; System.out.print("You entered weights: "); for(int i=0;i System.out.print(a[i]+" "); } sumWeight=getTotalWeight(a); avgWeight = sumWeight/a.length; System.out.println(); System.out.println(); System.out.printf( "Total weight: %.2f", sumWeight); System.out.printf(" Average weight: %.2f", avgWeight); System.out.printf( " Min weight: %.2f ", getMinWeight(a)); return; } /* Add method definition here */ public static double getMinWeight(double a[]) { double min = a[0]; for(int i=0;i if(min>a[i]) { min = a[i]; } } return min; } public static double getTotalWeight(double a[]) { double sum = 0; for(int i=0;i sum+=a[i]; } return sum; } } every time I get a bigger number I seen to have a error on my code see image for better undertanding. PLEASE CORRECT MY CODE
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started