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
Hamish has created a website with an online booking system for his salon appointments. He wants to engage more with his customer
zubka84 [21]

Answer:

  1. Gather customer feedback: Email Survey
  2. Tell customers about the extended opening hours: Social Media Page
  3. Show customers Hamish’s latest hair looks: An online gallery
  4. Help customers find the new salon: A map

Explanation:

1. By sending a questionnaire or survey via email, Hamish can gather customer feedback. Customers can answer these questionnaires directly in attached questions. They can also give feedback over email. Email survery is an economical way to collect feedback and can be sent to a many customers at the same time.

2. Hamish can tell customers about opening hours by a Social Media Page is a mean to assist social media accounts through QR Codes. He can update with his salon information via this web page. When customers scan can see salon's logo, information etc on this page in order to follow.

3. Hamish can display his latest hair looks through an online gallery by sharing his photos to many people. These images are stored, organized  displayed and shared on the website (online gallery). This is a better option than using expensive albums and hard copies.

4. Hamish can help customers to find a new salon by providing a map on his website. This makes easier for customers to locate the new salon as map provides with the navigation information. Customers can get a route  from their current location to the salon.

5 0
3 years ago
The Zoom slider will allow users to _____.
NeX [460]
The Zoom slider will allow users to change the way the document appears on the screen
3 0
3 years ago
Read 2 more answers
When you pass an array to a method, the method receives ______.
7nadin3 [17]
The correct option is 3.
When an array is passed as a parameter to a function, it is usually passed as a reference parameter. What is actually passed is the address of its first element. Since arrays are typically passed by reference, it means that if the function changes the value of an element in an array, then the corresponding actual array will change that element. To declare an array of real values as parameter one has to specify the parameters.
4 0
3 years ago
An Excel formula always begins with a(n) ____.
Basile [38]
Every Excel formula begins with '=' (equality) sign.
7 0
3 years ago
Which two hardware features would a technician monitor within the bios if a computer was suspected of overheating?
Firdavs [7]
I would say probably the CPU Fan and the CPU clock speed 
4 0
3 years ago
Other questions:
  • Does any body like animal jam
    11·2 answers
  • Diane wants to maintain a record of percent change in sales from the year 2000 to the present year. She enters the values of per
    10·1 answer
  • A spreadsheet has some values entered: Cell A1 contains 10, cell A2 contains 14, cell A3 contains 7. You enter in cell A4 the fo
    15·2 answers
  • Which of the following does not illustrate the survey method of choosing a speech topic?
    6·2 answers
  • 4. A computer architect boasted that they were able to design a computer in which every instruction occupied exactly thirty-two
    8·1 answer
  • Why is know app downloading in my android phone even if I have 900 MB ???
    8·2 answers
  • How does PowerPoint know which objects to group? The objects are aligned side by side. The objects are placed in one part of the
    11·2 answers
  • POR FAVOR AYUDENME DIGAN SOLO 10 Ejemplos de Software de Sistema. SI NO REPRUEBO Y LE DOY CORONA
    14·2 answers
  • Which step do you think is most useful from big data life cycle and why?
    12·1 answer
  • Why do we buy new asset​
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!