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
Ksenya-84 [330]
3 years ago
12

Create a Racket procedure compute_pos that reads numbers from the keyboard until 0 is read, count how many positive numbers are

read, and also compute the sum of only positive numbers, and display the count and the sum of positive numbers in different lines. Note that 0 is not included in the computations.
Computers and Technology
1 answer:
Artyom0805 [142]3 years ago
8 0

Answer:

import java.util.Scanner;

public class Solution {

   public static void main(String args[]) {

       compute_pos();

     }

     

     public static void compute_pos(){

     Scanner scan = new Scanner(System.in);

     int sum = 0;

     int counter = 0;

     // Prompt the user to enter an input

     System.out.println("Enter your value");

     // user input is assign to the variable value

     int value = scan.nextInt();

     

     while(value != 0){

         if (value > 0){

             sum += value;

             counter++;

         }

         System.out.println("Enter your value");

         value = scan.nextInt();

     }

     // Display the value of sum to the user

     System.out.println("The sum of the positive number is: " + sum);

     // Display the value of counter to the user

     System.out.println("The number of positive number is: " + counter);

   }

}

Explanation:

The first line import the Scanner class which allow the program to read input from the user. The class Solution is then defined. Then the main method which signify the beginning of execution in the program is defined. A method is called inside the main method.

The method compute_pos is defined. Inside the compute_pos method, a scanner object scan is declared to accept input from the user via the keyboard.

The variable sum and counter is declared and assigned to 0.

A prompt is displayed to the user to input a value. The user input is accepted and stored in the variable value.

Then a while loop is use to check the user input if it is not equal to zero. If it is equal to zero, the loop will end. Inside the loop, we first check to see if the user input is greater than 0, if it is, we add it to the variable sum and increase our counter by 1. At the end of the loop, a prompt is again display to accept input from the user.

Outside the loop, we display the sum and counter to the user.

You might be interested in
When you are making multiples of a brownie recipe, you cannot - without great difficulty - use a fraction of an egg. The calcula
Lera25 [3.4K]
The answer is one ☝️ question for the poll of a vote
5 0
2 years ago
True or false: Information security primarily relies on technical approaches such as multifactor authentication or data encrypti
Brilliant_brown [7]

TRUE, that is a one-sided answer. One of the biggest examples is virtually unhackable blockchains.

8 0
2 years ago
Each codec is stored within a file called a(n) ____ file.
frutty [35]
Im like 90% sure its a container file
5 0
3 years ago
Which correctly shows the configuration of boxes in the View tab that allow the indents to be changed?
den301095 [7]
The correct answer is B. Got it right on my review
4 0
3 years ago
Write a python program to calculate the sum of three numbers and as well require the user to input the numbers.​
beks73 [17]

Answer:

numbers = []

for i in range(3):

 numbers.append(eval(input("Enter number: ")))

print('Sum is:', sum(numbers))

Explanation:

You want to use a loop to prevent repeating your code.

8 0
2 years ago
Other questions:
  • A(n) ____________________ stores copies of data or programs that are located on the hard drive and that might be needed soon in
    9·1 answer
  • Can some one fix this <br> input ("Enter a number: ") <br> print (num * 8)
    9·1 answer
  • Write a loop that reads positive integers from standard input and that terminates when it reads an integer that is not positive.
    10·1 answer
  • How can you tell that a website is valid and reliable
    7·2 answers
  • Effective display designs must provide all the necessary data in the proper sequence to carry out the task. Identify a recent pe
    12·1 answer
  • What are some options available in the Spelling and Grammar Checker in word?
    6·1 answer
  • You have just installed a new NIC in your PC to replace the old one that had started malfunctioning. What additional software mu
    15·1 answer
  • Write programs in python to display “Valid Voter”. (condition : age of person should be
    15·1 answer
  • Describe how serial data access finds data
    9·2 answers
  • What does c++ programming mean?
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!