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
If your database is in archivelog mode, how can you force an archive?
MA_775_DIABLO [31]

Answer: (B) Issue an alter system switch logfile command.

Explanation:

 When the database is in the archive log mode then, the issue in the alter system switch logfile command force the particular switch. It basically produce achieve redo log which is smaller in the size by the dedicated size of the parameter log buffer.

It also govern the particular size of the RAM (Random access memory) buffer by redo log.  This command is basically faster to return in the program by the use of redo log.

On the other hand, all the options are incorrect as this command only alter the system and does not alter the database. Therefore, Option (B) is correct.

 

8 0
3 years ago
To create a program in Scratch, you need to think systematically about the order of steps. This is known as
Katarina [22]
Sequence. I took the same test like 5 minutes ago and got a perfect score
4 0
3 years ago
1 what elements of composition are under your control in photoshop
inn [45]
Tone
Sharpness
Scale
Arrangement
7 0
3 years ago
Which of the following is an example of tangible property?
lyudmila [28]
<span>B an idea for an invention that your dad mentioned briefly but did not write down</span>
8 0
4 years ago
When the _____ logical operator is used to combine keywords, a search engine will retrieve all results containing either keyword
DanielleElmas [232]
OR! Because one OR the other (or both, as this is not an exclusive or) needs to be present in the search result.
8 0
3 years ago
Read 2 more answers
Other questions:
  • A __________ network is good for connecting computers over boundaries.
    6·2 answers
  • _____ are likely to support bigger government, social welfare programs, and legalized abortion.
    8·2 answers
  • You may be guilty of plagiarism even if
    13·1 answer
  • Which of the following best describes
    13·1 answer
  • What is the difference between MySQL and MariaDB?
    9·1 answer
  • Released in 1976, the Apple I was Apple Computer's first product.<br><br> O True<br> O False
    6·1 answer
  • A homeowner uses a smart assistant to set the house alarm, get packages delivery updates, and set time on the outdoor lights. Wh
    14·1 answer
  • A type of user interface that features on- screen objects, such a menus and icons, manipulated by a mouse.
    7·1 answer
  • ______________ are used to store information that will be referenced and manipulated in a computer program. They label data with
    6·1 answer
  • The _________________ can be used to repair common causes of unbootable operating systems. It is based on the Windows Preinstall
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!