1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
e-lub [12.9K]
4 years ago
5

Write a loop that reads positive integers from standard input and that terminates when it reads an integer that is not positive.

After the loop terminates, it prints out, on a line by itself and separated by spaces, the sum of all the even integers read, the sum of all the odd integers read, a count of the number of even integers read, and a count of the number of odd integers read, all separated by at least one space. Declare any variables that are needed. ASSUME the availability of a variable, stdin, that references a Scanner object associated with standard input.

Computers and Technology
1 answer:
Katena32 [7]4 years ago
4 0

Answer:

import java.util.Scanner;

public class num15 {

   public static void main(String[] args) {

   Scanner in = new Scanner(System.in);

       int sumEven =0;

       int sumOdds =0;

       int countEven =0;

       int countOdd =0;

       System.out.println("Enter numbers");

       int num = in.nextInt();

       if(num%2==0){

           sumEven = num;

           countEven++;

       }

       else{

           sumOdds =num;

           countOdd++;

       }

    while(num>0){

        System.out.println("Enter another number: ");

        num = in.nextInt();

        if(num%2==0){

            sumEven= sumEven+num;

            countEven++;

        }

        else{

            sumOdds = sumOdds+num;

            countOdd++;

        }

   }

       System.out.println("Sum of Odds "+sumOdds);

       System.out.println("Sum of Evens "+sumEven);

       System.out.println("Count Odds "+countOdd);

       System.out.println("Count Evens "+(countEven-1));

   }

}

Explanation:

The complete program in Java is given above

Using the scanner class the user is repetitively prompted to enter a number

The while(num>0) loop ensures that only positive numbers greater than 0 are entered, when 0 or a negative number is entered the loop terminates.

Within the while loop an if/else statement is used to keep track of the sumEvens, countEvens, sumOdds and countOdds

The values of these variables are printed on separate line

See code output attached.

You might be interested in
Which is the smallest form of data <br>a)bit <br>b)byte<br>c)nibble<br>d)8 binary digits<br>​
melomori [17]
A. bit, is your correct answer
4 0
3 years ago
A stock transfer from a storage bin in one warehouse to a storage bin in another warehouse is a possible scenario under which wa
elena55 [62]

Answer:

False

Explanation:

In business, a stock transfer from a storage bin in one warehouse to a storage bin in another warehouse is NOT a possible scenario under which warehouse movements can occur.

Cheers

5 0
4 years ago
What are the dominant InfoSec-related credentials used to document knowledge and/or experience?
timofeeve [1]

Answer:

One of the most widely cited information security certifications is the Certified Information Systems Security Professional (CISSP), offered by the International Information Systems Security Certification Consortium (ISC)2[1].

4 0
2 years ago
A museum is evaluating historical documents for authenticity, reviewing their physical condition, and categorizing them by subje
Natasha_Volkova [10]

The part of this process that could the museum automate easily is defining and assigning categories by subject.

<h3>What is Cloud backup?</h3>

Cloud backup is known to be a kind of service where  data and applications on a business's servers are known to be saved up and kept on a remote server.

Note that a lot of Businesses usually back up to their data to cloud so as to keep files and data in space and available when they need it  most especially in the times of a system failure, outage, etc.

Learn more  about museum  from

brainly.com/question/95815

6 0
2 years ago
A computer ____ is the amount of data (typically measured in bits or bytes) that a cpu can manipulate at one time.
Paul [167]
A computers millions of transistors can manipulate the data
3 0
3 years ago
Other questions:
  • Jim has entered the age of each of his classmates in cells A1 through A65 of a spreadsheet. Which function should Jim use to fin
    11·2 answers
  • She thinks it is a good idea to list the gasses bass ed on the the gas found in the atmosphere ...
    12·1 answer
  • In Google search results, how are organic links different from sponsored links?
    13·2 answers
  • Which is a difference between the systems development life cycle (SDLC) and extreme programming (XP)?
    7·1 answer
  • Write a program that calculates taxi fare at a rate of $1.50 per mile. Your pro-gram should interact with the user in this manne
    12·1 answer
  • The first synthesizers were small simple machines that were easy to use. a. true b. false
    12·1 answer
  • Complete function PrintPopcornTime(), with int parameter bagOunces, and void return type. If bagOunces is less than 2, print "To
    5·1 answer
  • How would asking questions or defining problems be used in this career?<br> -
    13·1 answer
  • Define stubs for the functions get_user_num() and compute_avg(). Each stub should print "FIXME: Finish function_name()" followed
    8·1 answer
  • How do i copy a canvas course from old class to new course.
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!