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]
4 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]4 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
Discuss briefly general-purpose graphicsprimitives that contain 2D graphics library.
Zina [86]

Answer:

  General purpose graphics primitives that contain 2D graphic library as, it is used in graphics processing unit which typically manage computation for computer graphics. Graphic primitives contain basic element such as lines and curves. Modern 2D computer graphic system that operate with primitives which has lines and shapes. All the elements of graphic are formed from primitives.

8 0
3 years ago
Who wrote the book of luke​
netineya [11]
Luke himself wrote t the book
5 0
3 years ago
Which command is used to encrypt all passwords in a router configuration file?
Veseljchak [2.6K]

Answer:

Service Password encryption

Explanation:

It is noted that the command used on routers, to get the data of all the passwords in a router configuration file encrypted is the service password encryption.

Service password encryption solely affects plain text passwords types that includes that of the line passwords or that of the enable password. The feature uses a simple substitution method to create a "secure" non-text password displayed in the configuration.

8 0
3 years ago
Someone who buys a song online and copies it for friends is violating
Anon25 [30]

Answer:A

Explanation:

5 0
4 years ago
Read 2 more answers
Help need urgently answer ​
skad [1K]

Answer:

Explanation:

b

6 0
3 years ago
Read 2 more answers
Other questions:
  • What is the main benefit of seeing your document in Page Break Preview?
    9·2 answers
  • After a new technology is purchased,what are some additional costs that must be incorporated into an upgrade budget?
    6·1 answer
  • Write a program that includes functions to calculate feet to inches, inches to feet, feet to yards, and yards to feet. Then, acc
    9·2 answers
  • In the Mouse Properties window, you can?
    8·1 answer
  • We all had the unfortunate experience of seeing how computers can, at times, make life's journey about more difficult. This is e
    13·1 answer
  • Briefly explain what an array is. As part of your answer make use of a labelled example to show the declaration and components o
    5·1 answer
  • HELP ASAP!!!!<br> I don't know the code to these images and I need that code now.
    12·1 answer
  • Help<br> SOS<br> Quick <br><br><br><br><br> Hurry
    5·1 answer
  • Saitama And Tatsumaki Both Go Shopping Together ,Both have Have 50 loafs of bread , And Saitama takes 43 , How much do Tatsumaki
    14·1 answer
  • Which is the fastest memory in computer​
    9·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!