Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Assignment #2 will be the construction of a program that reads in an unspecified number of integers from standard input, performs some calculations on the

Assignment #2 will be the construction of a program that reads in an unspecified number of integers from standard input, performs some calculations on the inputted numbers, and outputs the results of those calculations to standard output. The numbers could be delimited by any kind of whitespace, i.e. tabs, spaces, and lines (Note that if you use the Scanner class, you do not have to worry about these delimiters. They will be taken care of). Your program will continue to read in numbers until the number 0 is entered. Zero is an even number. At this point, the calculations will be outputted in the following format:

The maximum integer is 0

The count of even integers in the sequence is 1

The smallest odd integer in the sequence is 0 T

he sum of negative integers is 0

This means that using all numbers your program reads (including the last number 0), you need to find the maximum, count how many even integers (can be divided by 2, num%2 == 0), compute the smallest odd integer (cannot be divided by 2, "num%2 != 0"), and compute the sum of negative integers. You should not use arrays for this assignment. You should use a loop to read the input and doing the calculation.

Note that the above is an output for the first test case. For other test cases, you will have different numbers.

Do not prompt to query for the numbers. The number 0 is included in the sequence of integers and should be included in all of your calculations.

Download the following input files, and save them in the same directory as Assignment2.java is located to test for test cases.

input 1

0

output 1

The maximum integer is 0

The count of even integers in the sequence is 1

The smallest odd integer in the sequence is 0

The sum of negative integers is 0

input 2

- 1 2 0

output 2

The maximum integer is 2

The count of even integers in the sequence is 2

The smallest odd integer in the sequence is -1

The sum of negative integers is -1

input 3

- 1 -2 -45 -901. 23 679 900

output 3

The maximum integer is 679

The count of even integers in the sequence is 4

The smallest odd integer in the sequence is -45

The sum of negative integers is -138

input 4

4 -3 0 -1 2

output 4

The maximum integer is 4

The count of even integers in the sequence is 2

The smallest odd integer in the sequence is -3

The sum of negative integers is -3

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

Professional Microsoft SQL Server 2014 Integration Services

Authors: Brian Knight, Devin Knight

1st Edition

1118850904, 9781118850909

More Books

Students also viewed these Databases questions