NOT ABLE TO CORRECT THIS CODE..
import java.text.DecimalFormat;
public class PeopleWeights {
public static void main(String[] args) {
DecimalFormat decFor = new DecimalFormat("0.00");
int i = 0;
int n = 5;
double arr[]=new double[n];
for(i = 0; i < n; i++){
System.out.println("Enter weight " + (i+1)+": ");
}
System.out.print("\nYou entered: ");
for(i = 0; i < n; i++){
System.out.print(arr[i] + " ");
}
System.out.println();
double total = 0;
double max = 0;
for(i=0; i<n; i++){
if(max < arr[i]){
max = arr[i];
}
total = total + arr[i];
}
DecimalFormat df = new DecimalFormat("#.##");
double average = total/n;
System.out.println("Total weight: "+ df.format(total));
System.out.println("Average weight: "+ df.format(average));
System.out.println("Max weight: "+ df.format(max));
return;
}
}
THIS ARE THE ERRORS I KEEP GETTING.
- Compare output 0/1 Input 236 89.5 142 166.3 93 Your output starts with Enter weight 1: Enter weight 2: Enter weight 3: Enter weight 4: Enter weight 5:
You entered: 0.0 0.0 0.0 0.0 0.0 Total weight: 0 Average Expected output starts with Enter weight 1: Enter weight 2: Enter weight 3: Enter weight 4: Enter weight 5:
You entered: 236.0 89.5 142.0 166.3 93.0
- Compare output 0/1 Input 123.4 56 98 174 215.8 Your output starts with Enter weight 1: Enter weight 2: Enter weight 3: Enter weight 4: Enter weight 5:
You entered: 0.0 0.0 0.0 0.0 0.0 Total weight: 0 Average Expected output starts with Enter weight 1: Enter weight 2: Enter weight 3: Enter weight 4: Enter weight 5:
You entered: 123.4 56.0 98.0 174.0 215.8
- Compare output 0/1 Input 236 89.5 142 166.3 93 Your output starts with Enter weight 1: Enter weight 2: Enter weight 3: Enter weight 4: Enter weight 5:
You entered: 0.0 0.0 0.0 0.0 0.0 Total weight: 0 Average weight: 0 Max weight: 0
Expected output starts with Enter weight 1: Enter weight 2: Enter weight 3: Enter weight 4: Enter weight 5:
You entered: 236.0 89.5 142.0 166.3 93.0 Total weight: 726.8
- Compare output 0/1 Input 236 89.5 142 166.3 93 Your output starts with Enter weight 1: Enter weight 2: Enter weight 3: Enter weight 4: Enter weight 5:
You entered: 0.0 0.0 0.0 0.0 0.0 Total weight: 0 Average weight: 0 Max weight: 0
Expected output starts with Enter weight 1: Enter weight 2: Enter weight 3: Enter weight 4: Enter weight 5:
You entered: 236.0 89.5 142.0 166.3 93.0 Total weight: 726.8 Average weight: 145.35999999999999
- Compare output 0/1 Input 236 89.5 142 166.3 93 Your output Enter weight 1: Enter weight 2: Enter weight 3: Enter weight 4: Enter weight 5:
You entered: 0.0 0.0 0.0 0.0 0.0 Total weight: 0 Average weight: 0 Max weight: 0
Expected output Enter weight 1: Enter weight 2: Enter weight 3: Enter weight 4: Enter weight 5:
You entered: 236.0 89.5 142.0 166.3 93.0 Total weight: 726.8 Average weight: 145.35999999999999 Max weight: 236.0
- Compare output 0/1 Input 123.4 56 98 174 215.8 Your output Enter weight 1: Enter weight 2: Enter weight 3: Enter weight 4: Enter weight 5:
You entered: 0.0 0.0 0.0 0.0 0.0 Total weight: 0 Average weight: 0 Max weight: 0
Expected output Enter weight 1: Enter weight 2: Enter weight 3: Enter weight 4: Enter weight 5:
You entered: 123.4 56.0 98.0 174.0 215.8 Total weight: 667.2 Average weight: 133.44 Max weight: 215.8