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
AnnZ [28]
3 years ago
8

Write a JAVA program that repeatedly prompts your user for a number, uses a recursive function to calculate the product of that

number times three (3), and displays the product. Select a sentinel value that allows your user to quit. Do NOT use the multiplication operator (*) in your proposed solution.

Computers and Technology
1 answer:
polet [3.4K]3 years ago
6 0

Answer:

// Scanner class is imported to receive user input

import java.util.Scanner;

// class Solution is defined  

public class Solution{

   // recursive function to calculate  

   // multiplication of two numbers

   // the second number is initialised to 3

   // it return the product

   public static int product(int x, int y)

   {

       // first it check if 3 is not 0

       // then it uses repetitive addition to get the product

       // it continues till 3 becomes 0

       if (y != 0)

           return (x + product(x, y - 1));

   }

     

   // main method to begin program execution

   public static void main (String[] args)

   {

       // Scanner object scan is initialize to receive input

       // via keyboard

       Scanner scan = new Scanner(System.in);

       // prompt is display to user to enter number

       System.out.println("Enter your number to multiply: ");

       // user input is assigned to x

       int x = scan.nextInt();

       // 3 is assigned to y which specify the number of times to multiply

       int y = 3;

       // while loop that continue to receive user input as long as it is not -1

       while(x != -1){

           // The result of the product is displayed

           System.out.println(product(x, y));

           // prompt is display to user to enter number

           System.out.println("Enter your number to multiply: ");

           // user input is assigned to x

           x = scan.nextInt();

       }

       

   }

}

Explanation:

The program is written in Java. An image of program output when the code is executed is attached.

A Scanner class is imported that allow program to read input. Then the product method is defined that compute the product of a number3 times using repetitive addition.

Then the method product is called inside the main method where the user is asked to continue input a number as long as the sentinel value (-1) is not entered.

You might be interested in
A researcher wants to do a web-based survey of college students to collect information about their sexual behavior and drug use.
finlep [7]

The answer is already given at the end of the question; solely by the magnitude or severity of expected harm

When assessing risks of harm associated with participation in a research study, the probability of harm and the risk of the severity of harm are two distinctive elements of risk that must be considered. In probability of harm, the fact that not all possible harms are equally probable should be considered. How these two elements occur is a crucial factor in determining the level of risk of harm in a study. Given the sensitivity of the information in the case scenario above, the probability that an individual subject could be identified is low while the magnitude of the possible risk of harm is high.


5 0
4 years ago
Read 2 more answers
Which of the following statements are true regarding Zyvox? (Select ALL that apply.)
Alinara [238K]

Answer: A,C,E

Zyvox = linezolid

Explanation:

Zyvox posses an excellent Gram positive coverage, as well as MRSA and VRE. Zyvox is primarily cleaned by the liver, the MAO inhibitor is expected to be administered with care along with Scrotonergic agents like SSRI, antidepressants, and it must be well monitored.

Bone marrow suppression is toxicity related with time and not Nephrotoxicity. Bioavailability in Zyvox is very excellent ; with transition from IV.PO with a ratio of 1:1.

7 0
4 years ago
help:(What are the uses of various lights? How are they all different? How do you decide on their usage? How can you use natural
Monica [59]

Answer:

This is one of the most common types of lighting. Ambient light is a soft glow that blankets your space just enough for you to function without causing a harsh glare. In photography and cinematography, ambient light is considered the "natural light" within a room. In décor, ambient light is very similar, except you create the ambient light by making the room's lighting as natural and flat as possible. While ambient light is meant to get you safely from point A-to-B, it is not ideal for working closely with things or to highlight things around your space. When used correctly, ambient light creates a fantastic environment to relax from an overly stressful day or to have a warm conversation with an old friend. Ambient lighting is often referred to as mood lighting, because this light captures the soft curves of your face and allows your pupils to dilate slightly (a physical sign of affection). Some yoga studios have even begun using the softer ambient lighting in their classes to help draw stress from the body. This is a smaller more concentrated light. You want task lighting around when you’re working. In fact, some people call it office lighting. Task lighting is meant to help you see when you’re doing projects in which you need a finer light, such as, reading, cooking, writing, sewing and many other things. Task lighting only works well when it is used as a contrasting light. For example, if you have a low lit room with a swing arm lamp turned on over your desk, the light over the desk surface will be more effective with less glare or shadow-effect than if the entire room was lit with a brighter light. Task lighting helps naturally stimulate your brain. The contrasting light allows you to be more alert and concentrated. This will help you see more details as you work, creating higher quality results. This is why many businesses choose to use task lighting in their offices.

Explanation:

5 0
3 years ago
ساعدوني على الإجابة على هذه الأسئلة
aleksandr82 [10.1K]

Answer:

Can you Translate for Russian or Eanglish

Explanation:

7 0
3 years ago
HTML tags normally come in pairs like and The end tag is written like the start tag, but with a backward slash inserted before t
baherus [9]

Answer:

<bold> Hm ok, what is the question? </bold>

4 0
4 years ago
Other questions:
  • While a hard drive is running, even a slight bump against the computer may cause the
    9·2 answers
  • Explain briefly the purpose of the Computer Management Console in Microsoft Windows.
    12·1 answer
  • Use the line of code below to choose the correct answer
    10·2 answers
  • How has information technology made piracy possible
    14·1 answer
  • What new information, strategies, or techniques have you learned that will increase your technology skills?
    14·1 answer
  • Hardware refers to programs and protocols used on a computer system.<br><br> True<br> False
    8·2 answers
  • JAVA
    10·1 answer
  • Determine what is printed by the following code.
    8·1 answer
  • What is a monitor?<br>i can ask everyone ​
    15·1 answer
  • How to turn robot voice like real human voice.
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!