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
MrRissso [65]
3 years ago
6

Given positive integer numinsects, write a while loop that prints that number doubled without reaching 100. follow each number w

ith a space. after the loop, print a newline. ex: if numinsects

Computers and Technology
2 answers:
ELEN [110]3 years ago
8 0
Please provide the language you're using when you ask for programming help, otherwise you aren't going to get the answer that you are looking for.

Here it is in Java, and I'm assuming the number is given via user input? Otherwise, just remove the user input function and replace the integer with a value of your choice. Note, that this isn't the full code; only what is relevant to the question.


public static void main(String[] args) {
    int num = numInput(10);
    printDoubles(num, 100);  // You can create a user input function for
                                             // maxValue if you wanted to.
}

/**
 * Receives user input between 0 and the absolute value of maxInput.
 * @param maxInput The largest absolute value that can be input.
 */
private static int numInput(int maxInput) {
    Scanner sc = new Scanner(System.in);

    maxInput = Math.abs(maxInput);

    int num = 0;
    while (!(num > 0 && num <= maxInput)) {
        num = sc.nextInt();

        if (!(num > 0 && num <= maxInput)) {
            System.out.println("Input too small or too large");
        }
    }

    return num;
}

/**
 * Continues to print out num doubled until maxValue is reached.
 * @param num The number to be printed.
 * @param maxValue The maximum value (not including in which num can                                       be doubled to.
 */
private static void printDoubles(int num, int maxValue) {
    if (num >= maxValue) {
        System.out.println("No output.");
    }

    while (true) {
        if (num >= maxValue) {
            break;
        }

        if (num < maxValue) {
            System.out.print(num + " ");
        }

            num *= 2;
    }

    System.out.println();
}

fredd [130]3 years ago
3 0

Answer:

while (numInsects < 100) {

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

        numInsects = numInsects * 2;

     }

     System.out.println();

Explanation:

Changed it to 100 to fit with your question

You might be interested in
What is output if the user enters -5?
7nadin3 [17]

Answer:

The left

Explanation:

6 0
2 years ago
Read 2 more answers
3. Radheshree has to complete her assignment and submit it on the next day. While typing
Dafna1 [17]

Answer:

she can use the onscreen keyboard

this application is present in accessories file in the windows

5 0
2 years ago
Guys Do you know about e-waste recycling well ?
TEA [102]
<span>E-waste is a popular name for elecronics at the end of their "useful life".. computers, tv, steros, copiers, and fax mations are some common products. many of them can be reused, refurbished, or recycled. 
</span>
4 0
3 years ago
Read 2 more answers
I need help with Exercise 3.6.7: Sporting Goods Shop in CodeHS. ASAP
attashe74 [19]

Answer:

OK

Explanation:

7 0
3 years ago
You have several reference computers. The computers are configured to always start from a local hard disk drive. You plan to cap
aivan3 [116]

Answer:

it is C.

Explanation:

3 0
3 years ago
Other questions:
  • What event in the 1970s contributed to the current
    6·2 answers
  • Java provides a(n) ____ class, which contains many useful methods for manipulating arrays.
    5·1 answer
  • Why is it a mistake to put email addresses of people who don't know each other in the "To:" field?
    8·2 answers
  • Create a program to calculate the wage. Assume people are paid double time for hours over 60 a week. Therefore they get paid for
    10·1 answer
  • What piece of software tells the operating system how to use a specific hardware device? a. User interface b. System service c.
    14·1 answer
  • Choose the word that best completes this sentence. ____________ should cover every part of the worksite.
    10·2 answers
  • Paul has been working long hours. He is tired and distracted by family issues,
    10·1 answer
  • All of the following are examples of service learning opportunities exept
    11·1 answer
  • The response from a Google Form can be seen in how many ways?
    10·1 answer
  • What is multimedia hard ware? Write any four examples of multimedia hardware. <br>​
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!