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
This morning when Paul turned on his computer at work, it would not boot. Instead, Paul reported that he heard a loud clicking n
IRISSAK [1]

Answer:

The problem with Paul's computer is that the magnetic hard drive failed.

Explanation:

A magnetic hard drive or hard disk is a non-volatile storage device, which is used to store different information on a computer.

The magnetic disk is made up of numerous magnetic plates, these plates are divided into sectors and tracks. A spindle is present in the middle to rotate the combined plates or the whole unit.

When there is a clicking noise coming from the magnetic disk, it could mean that one of the plates is damaged or if the power to the computer is inconsistent. This can greatly affect the performance of your computer.

3 0
4 years ago
Was the big blue button thing a good decision or bad?<br> *I think it was a bad idea.
Gala2k [10]

sorry i just got banned so delete this answer plz i was banned and i wanted to see if they unbanned me

8 0
3 years ago
Read 2 more answers
Question #4
Yuliya22 [10]

Answer:

tuple

Explanation:

the inner machinations of my mind ar- hey wait i´m not Patrick

8 0
3 years ago
How is data written to a blockchain?
NikAS [45]
<h2>APPEND ONLY</h2>

Unlike traditional databases, blockchain is designed to be an "append-only" data structure. That means you can only append new data in the form of additional blocks, which will then be chained together with previous blocks of data. All data is permanently stored across more nodes and cannot be altered.

6 0
3 years ago
Skills that are in demand for mobile computing-related positions include _____.
PtichkaEL [24]

Answer:

web analytics and joystick manufacturing

hope it helped !!

7 0
3 years ago
Read 2 more answers
Other questions:
  • Assume that to_the_power_of is a function that expects two int parameters and returns the value of the first parameter raised to
    11·1 answer
  • Select the correct answer.
    9·2 answers
  • If you select three separate parcels from a parcel feature class, how many rows would be selected in the associated attribute ta
    13·1 answer
  • "Common knowledge" must always be credited or else it is considered plagiarism?<br> True<br> Fales
    5·1 answer
  • Why laptop computer is called micro computer?​
    8·1 answer
  • We wish to design a decoder, with three inputs, x, y, z, and eight active high outputs, labeled 0, 1, 2, 3, 4, 5, 6, 7. There is
    5·1 answer
  • Who are the people responsible for maintaining and controlling computer networks within an organization?
    10·1 answer
  • Someone please help me
    6·1 answer
  • Fill the labels!! Please quickly I need help quickly
    9·1 answer
  • This code is supposed to accept a word as input, and then print that word to the screen.
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!