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
geniusboy [140]
3 years ago
6

4.2.3: Basic while loop expression. Write a while loop that prints userNum divided by 2 (integer division) until reaching 1. Fol

low each number by a space. Example output for userNum = 40: 20 10 5 2 1 Note: These activities may test code with different test values. This activity will perform four tests, with userNum = 40, then with userNum = 2, then with userNum = 0, then with userNum = -1. See "How to Use zyBooks". Also note: If the submitted code has an infinite loop, the system will stop running the code after a few seconds, and report "Program end never reached." The system doesn't print the test case that caused the reported message.

Computers and Technology
2 answers:
Grace [21]3 years ago
7 0

Answer:

def dividedByTwo(userNum):

   out = []

   num = userNum  

   while num > 1:

       num = num//2

       out.append(num)

   try:

       if out[-1]==1:

           print(str(userNum) + ': ' + str(out))

       else:

           print("Program end never reached.")

   except:

       print("Program end never reached.")

userNum = int(input())

dividedByTwo(userNum)

Explanation:

We created a function called dividedByTwo that receives the user input, inside the function is a while loop that just allows numbers greater than one to avoid an infinite loop, this while loop will finish when the division reaches one; finally, an if statement checks if 1 was reached, otherwise, an error message will prompt.

The output of the testing in the image down below

wlad13 [49]3 years ago
4 0

Answer:

import java.io.*;

import java.util.Scanner;

class divide {

public static void main (String[] args) {

    Scanner num=new Scanner(System.in);//scanner object.

    int userNum=num.nextInt();

    while(userNum>1)//while loop.

    {

        userNum/=2;//dividing the userNum.

        System.out.print(userNum+" ");//printing the userNum.

    }

}

}

Input:-

40

Output:-

20 10 5 2 1

Input:-

2

Output:-

1

Input:-

0

Output:-

No Output

Input:-

-1

Output:-

No Output.

Explanation:

In the program While loop is used.In the while loop it divides the userNum by 2 in each iteration and prints the value of userNum.The inputs and corresponding outputs are written in the answer.

You might be interested in
How do you use a iPad when it has a password ?
BaLLatris [955]
Take it to the Apple Store and they will help you or you can go on their site and press "Forgot Apple ID." If you choose the second option you have to enter the first and last name, and the email you used for the iCloud on the iPad. 
6 0
3 years ago
Read 2 more answers
Which of the following are agricultural industry clusters? Human population systems, computer technoloy biotechnology or food pr
GalinKa [24]

Biotechnology

Food Products and Processing Systems.

Further explanation

Career clusters help prepare learners with knowledge that they need to use towards achieving their career goals. One such career cluster is the Agriculture, Food, and Natural Resources career cluster which is divided into seven pathways. They include:

  • Food Products and Processing Systems.
  • Biotechnology Systems
  • Agribusiness Systems
  • Plant Systems
  • Animal Science
  • Environmental Service Systems
  • Natural Resource Systems

This brings us to our answers above. Those working in the Food Products and Processing Systems pathway are responsible in discovering new food sources and coming up with ways to process and store food set out by industry regulation. On the other hand, biotechnology systems deal with techniques that use science to solve problems concerning living organisms and anyone thinking about pursuing this pathway ought to demonstrate competence in the application of biotech in the context of Agriculture, Food, and Natural Resources.

Learn about Agriculture, Food, and Natural Resources career cluster

brainly.com/question/6457497

brainly.com/question/11364780

#LearnWithBrainly

6 0
2 years ago
What could prevent ping or traceroute responses from reaching the originating device beside network connectivity issues?
zysi [14]
Many admins set their firewalls to drop echo-request packets to prevent their networks from being mapped via "Ping Sweeps".

A remote possibility is that there's too many hops between the source and target and the packet's TTL expires.
3 0
3 years ago
I will give free brainiest if you guess my favorite car among these 3
erastovalidia [21]

Answer:

LaFerrari

Explanation:

8 0
3 years ago
Read 2 more answers
What happens during an Active object's animation sequence action?
RoseWind [281]

Answer:

B. The Active object's animation stops looping.

Explanation:

As the new event happens, the loop tells it to happen by stopping. And hence, B is the correct option out here. Neither A or C and Nor D is the correct option. The animation does not end here, and the next event takes place. Also, the active object's animation does not change the speeds. Hence, the correct option here is certainly the B.

4 0
3 years ago
Other questions:
  • The publisher tab in the application control allows you to manage the various certificates that are used to do what to binaries?
    8·1 answer
  • A(n) __________ can include a computer's full operating system, applications, and system settings, including security and config
    7·1 answer
  • Write code that inserts userItem into the output string stream itemsOSS until the user enters "Exit". Each item should be follow
    5·1 answer
  • What do economists call a decline in the real GDP combined with a temporary rise in price level?
    8·2 answers
  • When planning a backup strategy, ideally one needs to prioritize important data and only back up what is absolutely necessary fo
    15·1 answer
  • Select the correct answer from each drop-down menu. Which IF formulas are valid? _____ and _____ are valid IF formulas.
    6·1 answer
  • How can you represent a graphic element in a wireframe?
    5·1 answer
  • Which generation of computer is most popular and why?
    9·1 answer
  • You are making a game! The player tries to shoot an object and can hit or miss it. The player starts with 100 points, with a hit
    13·1 answer
  • What are tasks performed by pascaline?​
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!