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
Modify the CountByFives application so that the user enters the value to count by. Start each new line after 10 values have been
adoni [48]

Answer:

The modified program is as follows:

import java.util.*;

public class CountByAnything{  

public static void main (String args[]){

   Scanner input = new Scanner(System.in);

final int START = 5;

final int STOP = 500;

int countBy; int count = 0;

System.out.print("Count By: ");

countBy = input.nextInt();

final int NUMBER_PER_LINE = 10;

for(int i = START; i <= STOP; i += countBy){

System.out.print(i + " ");

count++;

if(count == NUMBER_PER_LINE){

System.out.println();

count = 0;} } } }

Explanation:

To solve this, we introduce two variables

(1) countBy --> This gets the difference between each value (instead of constant 5, as it is in the program)

(2) count --> This counts the numbers displayed on each line

The explanation is as follows:

<em>final int START = 5; </em>

<em>final int STOP = 500;</em>

This declares countBy and count. count is also initialized to 0

int countBy; int count = 0;

This prompts the user for countBy

System.out.print("Count By: ");

This gets value for countBy

countBy = input.nextInt();

<em>final int NUMBER_PER_LINE = 10;</em>

This iterates through START to STOP with an increment of countBy in between two consecutive values

for(int i = START; i <= STOP; i += countBy){

This prints each number

System.out.print(i + " ");

This counts the numbers on each line

count++;

If the count is 10

if(count == NUMBER_PER_LINE){

This prints a new line

System.out.println();

And then set count to 0

count = 0;}

6 0
2 years ago
What office application has animations on the home ribbon?
Eva8 [605]
It's Microsoft office power point presentation.
3 0
3 years ago
Read 2 more answers
A search engine displays a list of webpage names that contain the search text. what is the term for that list?
Minchanka [31]
<span>A search engine displays a list of webpage names that contain the search text. The term for that list is hit.
Basically, what this term refers to is the number of visits, or a number of downloads that happened on that particular webpage. It is a good tool to measure web traffic, or how much that page is visited.
</span>
6 0
3 years ago
(15) What is the best definition of a contextual tab?
katen-ka-za [31]

  1. What is the best definition of a contextual tab-<u>(c) A tab that appears in context with what you are working on</u>
  2. A theme can be applied to-<u>(d) All of the answers are correct</u>

Explanation:

  1. What is the best definition of a contextual tab-<u>(c) A tab that appears in context with what you are working on</u>
  2. A theme can be applied to-<u>(d) All of the answers are correct</u>
  3. What is the difference between Reading view and Slide Show view-<u>(c) Slide Show view contains annotation tools while Reading view does not</u>
  4. Which of the following is not a view available from the Presentation Views section of the View tab-<u>(a) Slide Show</u>
  5. Where can you find the command to access slide, note, or handout masters-<u>(d) View tab</u>
  6. To rotate a text box, which handle would you use-<u>(d) You must use the commands on the Home tab</u>
  7. To change a black and white, boring presentation into something a bit more pleasing to the eye, what option would be best-<u>(b) Templates</u>
  8. The area on the top of your PowerPoint screen, as seen in the image, is commonly referred to as the what-<u>(a) Menu Options</u>
  9. What does it mean when a command button is grayed out-<u>(c) The command is disabled and requires an action first.</u>
  10. The area on a slide that holds text that will appear in the presentation outline is a-<u>(a) text box</u>
  11. To easily find a presentation that you were working on earlier today, you could-(<u>c) all of the above</u>

6 0
3 years ago
Cuáles son las partes más importantes de una flor​
castortr0y [4]

Answer:

estas son

Explanation:

El cáliz. Está formado por los sépalos, que son un conjunto de hojas verdes en la base de la flor.

La corola. Está formada por los pétalos que son hojas coloreadas en el interior de los sépalos.

Los estambres. Son los órganos masculinos de la flor. ...

El pistilo. Es el órgano femenino de la flor.

7 0
2 years ago
Other questions:
  • true /falseCompression of entries in the term-document matrix can be used to reduce run-time storage and execution-time requirem
    10·1 answer
  • The mods have peanuts for brains (it's true, I lost like 1k points to them for no reason)
    12·1 answer
  • Limitations of the information systems used by tesco​
    7·1 answer
  • " In which software generation did the distinction between systems programmers and other programmers first surface?"
    15·1 answer
  • What should you do to help prepare yourself for the delivery of your presentation? you can chose more then one
    8·1 answer
  • Which processor family is most likely found on recent gaming laptops (Gaming laptops require a lot of computational power)?
    11·1 answer
  • What do level meters show?
    8·1 answer
  • Which best describes how a supporting database will be structured?
    10·1 answer
  • What is difference between base font and font tags​
    13·1 answer
  • Why is it easier to spot a syntax error than a logical error?​
    10·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!