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
A series of inventions led to the creation of the electronic digital computer shortly after this war..
lesantik [10]
What is world war 2? bob
4 0
2 years ago
How teachers apply stenhouse theory
Scilla [17]

Answer:

In curriculum, a vision of knowledge, the role of the educator and a concept of the process of education are all present. In this sense, Stenhouse suggests that the role of teachers and professors is fundamental in the elaboration and implementation of curriculum.

3 0
2 years ago
. In Laissez-faire Styleof Group Leadership, Members of the group are not given help inactivity plans by the leader only when it
Trava [24]

Answer:

The statement is false.

Explanation:

In Laissez-faire Style of group leadership, the members of the group are given all the responsibilities by the leader or the manager. The members of the group take all the decisions and control the working of the group. The manager provides with some guidance or support only when it is asked by the group members.

4 0
2 years ago
Casey Griggs is a very capable computer engineer. Recently, he noticed a problem that computer engineers have, and thought of a
diamong [38]

Answer:

serendipitous

Explanation:

this happened by chance in a positive manner.  

8 0
3 years ago
What was designed as an area where computer vendors could store data that is shielded from user activities and operating system
Nataliya [291]

Answer:

host protected area

Explanation:

7 0
2 years ago
Other questions:
  • Behaving in an acceptable manner in a workplace environment is referred to as workplace etiquette.
    12·2 answers
  • Write the definition of a function typing_speed, that receives two parameters. The first is the number of words that a person ha
    9·1 answer
  • You use Cat5e twisted pair cable on your network. Cables are routed through walls and the ceiling. A user puts a screw in the wa
    9·1 answer
  • Plz help me of this answer<br><br><br>language:python​
    7·2 answers
  • Moderate changes to existing processes falls under the _________ analysis. Business Process Automation (BPA) Business Process Im
    5·1 answer
  • Cheri needs to write a small program that interacts with the user. What step will allow her to do this?
    14·2 answers
  • What is the output?<br> &gt;&gt;&gt; phrase = "hello mom"<br> &gt;&gt;&gt; phrase upper()
    6·2 answers
  • What is star topology
    15·2 answers
  • You are an IT network administrator at XYZ Limited. Your company has critical applications running of its Ubuntu Linux server. C
    6·1 answer
  • Consider the following variable declarations and initializations.
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!