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
Arlecino [84]
3 years ago
15

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, the sum of all the even integers read. 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:
kolbaska11 [484]3 years ago
6 0

Answer:

Written in Java Programming Language

import java.util.Scanner;

public class Assign{

   public static void main(String [] args)    {

   Scanner stdin = new Scanner(System.in);

   int num,sum=0;

   System.out.println("Start Inputs: ");

   num = stdin.nextInt();

   while (num>=0) {

       if(num%2== 0)

       {

       sum+=num;    

       }      

       num = stdin.nextInt();

   }

   System.out.print("Sum of even numbers: "+sum);

   

   }

}

Explanation:

I'll start my explanation from line 4

This line initializes Scanner object stdin

Scanner stdin = new Scanner(System.in);

This line declares necessary variables and initializes sum to 0

   int num,sum=0;

This line prompts user for inputs

   System.out.println("Start Inputs: ");

This line reads user inputs

   num = stdin.nextInt();

This line checks is user input is not negative (It's a loop that will be repeated continually until a negative number is inputted)

   while (num>=0) {

This line checks if user input is an even number

       if(num%2== 0)

       {

If the above condition is true, this line calculates the sum of even numbers

       sum+=num;    

       }      

This line prepares the user for next input

       num = stdin.nextInt();

   }

This line prints the calculated sum of even number; If no even number is inputted, the sum will be 0

   System.out.print("Sum of even numbers: "+sum);

You might be interested in
A cloud implementation engineer successfully created a new VM. However, the engineer notices the new VM is not accessible from a
Rina8888 [55]

Answer:

Option A.

Explanation:

Incorrect subnet is the most likely problem in this scenario.

4 0
3 years ago
Paul is a baker who wants to improve his recipe for muffins because they turn out with a greasy flavor. What ingredient should h
Sergio039 [100]
Butter to Margarine

Cakes baked with butter usually always turns out to be greasy and heavy.

Hope this helps, good luck! (:
3 0
3 years ago
Read 2 more answers
Computers can accomplish many tasks today, but there are still some things they cannot do. Think of some of the things you would
postnew [5]
Record our dream.
Since it is from the future and advanced, it is invalid to argue back that the wish to record our dreams cannot be fulfilled.

From here you can elaborate more ...
7 0
3 years ago
How is the number 13,000 abbreviated in scientific notation?
Gennadij [26K]
<span> 13,000 is the same as 1.3 x 10^4</span>
3 0
3 years ago
Read 2 more answers
Which two statements give good definitions of financial credit
iren2701 [21]
The two <span>statements that give good definitions of financial credit are :            1) Balance Sheet & 2) Income Statement.  
</span>
1) Balance sheet shows the assets, liabilities, and net worth on a
    given date;
2) Income statement (profit & loss account), shows how the net income of
    the firm is arrived at over a stated period. 
Another statement is Cash flow statement, which shows the inflows and outflows of cash caused by the firm's activities during a given period of time.
3 0
3 years ago
Other questions:
  • What are the five types of pointing devices?
    11·1 answer
  • Write an application that allows a user to enter the names and birth dates of up to 10 friends. Continue to prompt the user for
    6·1 answer
  • How long did it take Linkedln to reach 1 million users?
    5·2 answers
  • If the physical memory size is doubled without changing any of its other parameters, the number of entries in the page table
    5·1 answer
  • 9. What is composition? Why is composition important?
    11·1 answer
  • The arguments in a method call are often referred to as ____ . The variables in the method declaration that accept the values fr
    10·1 answer
  • 5.During a recent network attack, a hacker used rainbow tables to guess network passwords. Which type of attack occurred
    9·1 answer
  • Which of the following transfer rates is the FASTEST?
    15·1 answer
  • Complete the sentence.<br><br> The internet is an example of a ___ .
    8·1 answer
  • Question 1
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!