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
True or false: all blockchains are programmed to have the same block time (confirmation time) as each other.
wariber [46]

Answer:

False

Explanation:

<em>The complexity of the hash, which is the hexadecimal number produced by the hashing process, determines the precise length of time required for block production. Thus, block times won't always be the same.</em>

4 0
1 year ago
The database structure in a dbms is stored as a _____.
Colt1911 [192]
This will be stored as a collection of files
6 0
3 years ago
What does artifishal inteligence mean
Umnica [9.8K]

looks Theory and development of computer systems able to perform tasks that normally requires human intelligence

4 0
2 years ago
Read 2 more answers
The Internet has been around for quite a while, but it did not have much impact on our everyday lives until the appearance of th
pishuonlain [190]

Answer:

The answer is "WWW".

Explanation:

WWW stands for World Wide Web, It is a combination of all Internet resources and users, that uses the hypertext transfer protocol. It provides world information that is available on the internet that is the expression of human knowledge. It is also known as a domain name that introduces resources or individual instances of the entire collection.

6 0
3 years ago
For each of the following memory accesses indicate if it will be a cache hit or miss when carried out in sequence as listed. Als
nika2105 [10]

Answer:

Explanation:

Operation Address Hit? Read Value

Read 0x834 No Unknown

Write 0x836 Yes (not applicable)

Read 0xFFD Yes CO

6 0
3 years ago
Other questions:
  • What does this say:<br> √ans
    6·2 answers
  • Virtual private network requires a secure remote connections<br><br> true or false?
    11·1 answer
  • What is the difference between edge and core networks?
    13·1 answer
  • Interruption attacks are also called ___ attacks:
    8·1 answer
  • If you copy a drawing from the Internet and use it in a report, you might be violating the artist's
    8·1 answer
  • First let 2161965 answer<br> and then you ..
    11·2 answers
  • A marketing firm has been hired to help a client understand how their online brand is perceived. The firm has set up a system to
    14·1 answer
  • Match each term in the second column with its correct definition in the first column. Write the letter of the term on the blank
    12·1 answer
  • Create a variable in php to store your university information and parse using jQuery Ajax and print your name. The variable must
    12·1 answer
  • Name any three areas of of application of excel.
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!