Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.

image text in transcribed

image text in transcribed

PLEASE CORRECT MY CODE

:Compare output 96.6 212.2 Input 150.5 120.1 175 Enter weight 1: Enter weight 2: Enter weight 3: Enter weight 4: Enter weight 5: Your output correctly starts with You entered weights: 96.6 212.2 150.5 120.1 175.0 Total weight: Average weight: Min weight: 754.40 150.88 96.60

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Conceptual Database Design An Entity Relationship Approach

Authors: Carol Batini, Stefano Ceri, Shamkant B. Navathe

1st Edition

0805302441, 978-0805302448

More Books

Students also viewed these Databases questions

Question

What are the stages of project management? Write it in items.

Answered: 1 week ago

Question

why do consumers often fail to seek out higher yields on deposits ?

Answered: 1 week ago

Question

=+industrial action Under what circumstances can unions strike?

Answered: 1 week ago

Question

=+What forms of industrial action are common?

Answered: 1 week ago