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]
2 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]2 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
Write the technical terms for the following statements: The repeated working capacity of computer.
ozzi

The technical terms for the statement "The repeatedly working capacity of computer" is  known to be "diligence.

<h3>Why is the working capacity of computer" known to be "diligence."?</h3>

The capacity of a computer is known to be one that carry out or performs a lot of task in a repetitive manner without getting tired and as such, one can say the computer is diligent.

Note therefore that The technical terms for the statement "The repeatedly working capacity of computer" is  known to be "diligence.

Learn more about computer from

brainly.com/question/24540334

#SPJ1

8 0
1 year ago
What kind of heat we feel from the sun
ivolga24 [154]

Is it solar heat? ultraviolet heat? UV?
6 0
3 years ago
Read 2 more answers
Write a program that determines the price of a movie ticket (similar to the one in the chapter). The program asks for the custom
goblinko [34]

Answer:

#include <iostream>

using namespace std;

int main() {

int age,time;

float price;

cout<<"Enter age:";

cin>>age;

cout<<"Enter time(in 24 hour clock for noon 1200):";

cin>>time;

if(age>13){

if(time<1700){

price=5;

}else{

price=8;

}

}else{

if(time<1700){

price=2;

}else{

price=4;

}

}

cout<<"Price: $"<<price<<endl;

}

Explanation:

Okay, here are the steps to be taken in order to be able to Write a program that determines the price of a movie ticket as given in details in the question above. Therefore, checked the steps below;

==> Input the age and the time.

==> If the age is not greater than 13, input the time(that is <1700) and follow it by imputing the price.

And if the age is greater than 13, you will also need to input the price. Just as below;

#include <iostream>

using namespace std;

int main() {

int age,time;

float price;

cout<<"Enter age:";

cin>>age;

cout<<"Enter time(in 24 hour clock for noon 1200):";

cin>>time;

if(age>13){

if(time<1700){

price=5;

}else{

price=8;

}

}else{

if(time<1700){

price=2;

}else{

price=4;

}

}

cout<<"Price: $"<<price<<endl;

}

6 0
3 years ago
To type the letter address, _________ space from the dateline
miskamm [114]

Answer: Double

Explanation:

I just took the test

4 0
3 years ago
Read 2 more answers
Write a program that asks the user to enter a birth year. the program should then indicate which generation a person of that yea
USPshnik [31]
Something like the following. Also you need to give what language you are using. Anyways, you should be able to convert this to your language of choice. 

<script type="text/javascript">
function checkGeneration() { 
   var gen = ["Baby Boomer ","Generation X","Xennials","Generation Y"];
   var reversestr = "";
   var getyear = window.prompt("Enter a 3 digit number: ");
    if (parseInt(getyear) <= 1964) {
        alert(gen[0]);   
    } else if(parseInt(getyear) <= 1979) {
        alert(gen[1]);
    } else if(parseInt(getyear) <= 1985) {
        alert(gen[2]);               
   }  else if(parseInt(getyear) <= 1995) {
        alert(gen[3]);
   }
 }
checkGeneration();
</script>
7 0
2 years ago
Other questions:
  • Which connector is most commonly used to connect printers to desktop pc systems?
    10·1 answer
  • In Word, blue underlining indicates which of these problems?
    12·1 answer
  • ICS facilitates the ability to communicate by using:
    7·1 answer
  • What is the Matlab command to create a column vector with 11 equally spaced elements, whose first element is 2 and whose last is
    8·1 answer
  • All states that have altered judicial selection techniques in recent years have adopted some form of:
    10·2 answers
  • Scenario
    7·1 answer
  • A business letter is not written:
    6·1 answer
  • the tool that is used on the form to display text that the user cannot change is a. textbox b. label c. button​
    9·1 answer
  • g Write a function named vowels that has one parameter and will return two values. Here is how the function works: Use a while l
    9·1 answer
  • Josh needs to write a research report for his Civics class. Which file type will allow him to save his file? (5 points)
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!