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
What summarizes a data source into a grid of rows and columns?
Ludmilka [50]
#1) What summarizes a data source into a grid of rows and columns?
Answer: A Database. A database is an organized collection of data. It is the collection of schemas, tables, queries, reports, views, and other objects. The data are typically organized to model aspects of reality in a way that supports processes requiring information.
4 0
3 years ago
Read 2 more answers
What are the three aspects to consider when taking and critiquing photograph?
svlad2 [7]
The angle
Steady Hands
Focusing on the right lighting
3 0
3 years ago
David wanted to build a Temple for God in________
Leona [35]

Answer: The answer would be Bethlehem!

4 0
3 years ago
Read 2 more answers
A speech why friends are important 2 min​
Gnoma [55]

Friends can challenge us, confuse us, and sometimes, we might wonder why we bother. But friendship is as important to our wellbeing as eating right and exercising. What’s more, friendships help us grow through each year of our lives.

The friends we meet in school teach us how to be patient, wait our turn, reach out, and try new hobbies. When we move into young adulthood we learn more about taking responsibility, finding a career path, and seeking out people as mentors.

As we continue into our 40s and beyond, we learn to weather the ups and downs in life, and once again friends provide a sounding board and place for us to grow. Friendship is key to our success with all our relationships and it can create a sense of purpose in our lives.

The people we bring into our lives as friends will show us how to forgive, laugh, and make conversation. The basic components of any relationship, from our marriage to our coworkers, are all founded in friendship. We learn how to interact with people because of our friends, even the ones that are opposite from us or share a different worldview.

We don’t just talk with others but learn from them. We understand the process of meeting new acquaintances and finding out what makes them tick. These people help push us out of our comfort zones while still providing a safe emotional space for us to be totally ourselves.

One of the most overlooked benefits of friendship is that it helps keep our minds and bodies strong. In fact, it’s as important to our physical health as eating well and keeping fit. A recent Harvard study concluded that having solid friendships in our life even helps promote brain health.

4 0
3 years ago
Jessica has pinned her favorite applications as icons on her desktop. She always clicks on these icons to work on them. Which us
Hatshy [7]

Answer:

Graphical User Interface (GUI)

Explanation:

Graphical User Interface clicking on various icons to perform a certain functionality. GUI is a form of user interface that allows users to interact with electronic devices through graphical icons and audio indicator such as primary notation, instead of text-based user interfaces or command line interface where you would have to type to run the program rather than just click it.

7 0
3 years ago
Other questions:
  • When you set the position property for a block element to absolute, the browser?
    8·1 answer
  • Question 4: What will be the output of the code? Show a complete analysis.
    6·1 answer
  • (01.05 LC)
    7·2 answers
  • Suppose that the domestic production of computer games creates enjoyment for those who play the games. Domestic production of co
    14·1 answer
  • You and your project team have been asked to generate a solution to a problem. The problem is not complicated, and you are sure
    6·1 answer
  • What invention in the past do you think had a significant impact on our culture/ lifestyle? What do you think will be invented/
    11·1 answer
  • (a) How many copies of the book titled "The Lost Tribe" are owned by the library branch whose name is "Sharpstown"? (b) How many
    10·1 answer
  • Think about that the C, B and S parameters of a Cache. Think about what happens to compulsory, capacity, conflict misses, if onl
    7·1 answer
  • Write a program in Python to sum to numbers:<br><br> Urgently needed, please.
    14·1 answer
  • kidede secondary school in Kotido district has been selected to participate in the final continental debating competitions with
    9·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!