answer.
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]
1 year 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]1 year 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]1 year 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
When creating a table in the relational database design from an entity in the extended e-r model, the attributes of the entity b
larisa86 [58]
No.  The attributes of the table correspond to columns within the table.  Each unique set of attribute values taken together correspond to table rows.  Sometimes referred to as "records".

8 0
1 year ago
What technique creates different hashes for the same password? ccna routing protocols final answers?
elena-s [515]
The answer is Salted Password Hashing.  The process is similar to hashing., but with a twist. A random value is introduced for each user. This salt value<span> is included with the password when the hash value is calculated and is stored with the user record. Including the salt value means that two users with the same password will have different password hashes.</span>
7 0
2 years ago
Write a static method named countLastDigits that accepts an array of integers as a parameter and examines its elements to determ
Crazy boy [7]

Answer:

See explaination for the program code

Explanation:

code:

public static int[] countLastDigits(int[] list) {

int[] count = new int[10];

for (int i = 0; i < list.length; i++) {

int digit = list[i] % 10;

count[digit]++;

}

return count;

}

8 0
2 years ago
Two women are on either side of a high fence. One of the women, named Apple- server, has a beautiful apple tree loaded with deli
ZanzabumX [31]

Answer:

ok cool

Explanation:

kkk

6 0
2 years ago
You are a network administrator for a large bagel manufacturer that has 32 bakeries located throughout the United States, United
Anni [7]

Answer:

See the components in explaination

Explanation:

In order to make it as IPv6, few key components should be supported, those components are given below:

The infrastructure must support the enhanced protocol StateLess Address Auto-Configuration (SLAAC).

Static addressing with DHCPv6, dynamic addressing with DHCPv6 and SLAAC are the methods used to configure the IPv6. The network administrator should able to understand and implement the IPv6 through the DHCPv6.

Other than the implementation, working of IPv4 and IPv6 are same. Therefore, the administrator need not to learn new information for its working.

As the IPv6 address length is 128-bit and purpose is for everything on line to have an IP address. It must allow the internet to expand faster devices to get internet access quickly.

The DHCPv6 is not supported by all windows. Therefore, network administrator should check the corresponding Operating system (OS) would support the DHCPv6 for IPv6.

The network administrator must have good knowledge and skills on the IPv6.

The above mentioned key components should be verified by the network administrator in order to support for IPv6 project with DHCPv6.

4 0
1 year ago
Other questions:
  • Janice is unsure about her future career path she has grown up on her family farm but she is also interested in medicine Janice
    5·1 answer
  • You have been tracking your exercise routine, which involves running, lifting weights, yoga, and stretching. You want to see wha
    15·2 answers
  • Because of the density of vehicle in urban areas, you should ____.
    8·2 answers
  • If the computer has an encrypted drive, a ____ acquisition is done if the password or passphrase is available. a. passive b. sta
    8·1 answer
  • Which of the following facts determines how often a nonroot bridge or switch sends an 802.1D STP Hello BPDU message?
    14·1 answer
  • A school principal trying to find out if parents will help buy new playground equipment shows digital leadership by.
    8·2 answers
  • Quantum units of information deploy the properties of entanglement and ____ to offer exponentially greater computing power.
    9·1 answer
  • When do images or graphics in Microsoft Word hurt the document rather than help
    9·1 answer
  • 12. Write C statement(s) that accomplish the following. a. Declare int variables x and y. Initialize x to 25 and y to 18. b. Dec
    12·1 answer
  • For a custom App uploaded to Microsoft Teams, if an organization wants to disallow users from updating the settings of the custo
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!