Question: Modify Examine1 code to use an if...if/else statement. Check each value entered by the user to determine if the user entered a negative number. If

Modify Examine1 code to use an if...if/else statement.

Check each value entered by the user to determine if the user entered a negative number. If so, program should count each negative number entered.

Once user has entered all numbers, program should print the total negative numbers entered by user.

Your program should print the average using the printf command and the number of negative numbers entered.

Note: You may include or exclude the negative numbers with your calculation.

This is the code for Examine1

import java.util.Scanner;

public class Examine1 {

public static void main(String[] args) {

Scanner input = new Scanner(System.in);

System.out.print("How many numbers would you like to enter? ");

int count = input.nextInt();

int sum = 0;

for (int i = 0; i < count; i++) {

System.out.print("Enter number #" + (i+1) + ": ");

int num = input.nextInt();

sum += num;

}

double average = (double) sum / count;

System.out.printf("The sum of the %d numbers is %d. ", count, sum);

System.out.printf("The average of the %d numbers is %.2f.", count, average);

input.close();

}

}

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!