Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Modern Dental Assisting

Authors: Doni Bird, Debbie Robinson

13th Edition

978-0323624855, 0323624855

Students also viewed these Programming questions