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
nadya68 [22]
3 years ago
8

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 the sum of all the even integers read and the sum of all the odd integers read(The two sums are separated by a space). Declare any variables that are needed.
Computers and Technology
1 answer:
puteri [66]3 years ago
5 0

Answer:

import java.util.Scanner;

public class num4 {

   public static void main(String[] args) {

     Scanner in = new Scanner(System.in);

     int sumOdds =0;

     int sumEvens =0;

     int num;

     do{

         System.out.println("Enter positive integers");

         num = in.nextInt();

         if(num%2==0){

             sumEvens+=num;

         }

         else if (num%2!=0){

             sumOdds+=num;

         }

     }while (num>0);

       System.out.println("The sum of evens: "+sumEvens);

       System.out.println("The sum of odds: "+sumOdds);

   }

}

Explanation:

  • Import Scanner class to prompt and receive user input
  • Declare the following variables and initialize them int sumOdds =0, int sumEvens =0, int num;
  • Create a do....while loop That continously prompts user to enter a positive number. The loop should terminate when a negative number is enters (n<=0)
  • Within the while loop use an if condition with the modulo (%) operator to determine even and odd numbers and add to the respective variables
  • Outside of the while loop Print sum of odds and sum of evens

You might be interested in
Pleas help I will give brainiest
stellarik [79]
1) A
2)D
3)C
4)A
5)D
Hope this will help u
5 0
3 years ago
Read 2 more answers
Software that interprets commands from the keyboard and mouse is also known as the
Stells [14]
A) operating system
It is going to let you "operate" it using the mouse and keyboard
4 0
3 years ago
Read 2 more answers
Alcohol is considered a _____ drug
andreyandreev [35.5K]
Bad.......................
8 0
4 years ago
Read 2 more answers
Alisha appears to be overconfident which makes her unapproachable to her employees. Which negative quality is she displaying?
sergeinik [125]

As the question states Alisha is displaying the quality of overconfidence. This can effect not only herself in her work but also others. She can be demotivated and may even lose confidence completely. This behavior can be fixed by approaching towards her. you can call her very assuming, boldfaced or impertinent

HOPE THIS HELPS. PLEASE THANK AND MARK AS BRAINLIEST : )

7 0
4 years ago
Read 2 more answers
Consider the following statement: ptrMemberVarType objectThree(objectOne); The values of the member variables of objectOne are b
MariettaO [177]

Answer: C) Member-wise initialization

Explanation:

 The member wise initialization is the shortest technique for initialize the various properties of the member into new structure. The initial value of the given properties are basically pass by the name to the member wise initialization.

The given statement is the type of value in which the member variable of the object one are copy into the member variable of the object three.

Therefore, this initialization process is basically known as member wise initialization.

 

8 0
4 years ago
Other questions:
  • Which BI tool or technique would be most useful in predicting the likelihood of a fire in a building? a. Data mining b. Dashboar
    9·1 answer
  • What are the pros and cons of editorial anonymity?
    13·1 answer
  • What is the name of the program that takes high-level code and transforms it into machine-level code?
    8·1 answer
  • Changes in the ownership of a file do not change the amount of data that is considered to belong to a user.
    12·1 answer
  • Which of these statements makes the most sense? a folder is contained within a file. a file is contained within a folder. a driv
    9·2 answers
  • A commercial depicts a teenager on a skateboard vandalizing a brick wall. This is an example of:
    11·2 answers
  • Which is a benefit of getting information from a government website?
    15·2 answers
  • 9. Which is an example of a function?<br>(1 Point)<br>=A1 +A2<br>=SUM(A1:A3)<br>=ADD(A1:A3)​
    14·2 answers
  • Define the computer with its workintg principple
    7·1 answer
  • Question #2: How would you demonstrate professionalism in a video call with a teacher? Edmentum Digital world Please Help!!
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!