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
GaryK [48]
2 years ago
6

Write a while loop that prints userNum divided by 2 (integer division) until reaching 1. Follow 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
1 answer:
jasenka [17]2 years ago
4 0

Answer:

public class Main

{

public static void main(String[] args) {

    int userNum = 40;

    while(userNum > 1){

        userNum /= 2;

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

    }

}

}

Explanation:

*The code is in Java.

Initialize the userNum

Create a while loop that iterates while userNum is greater than 1. Inside the loop, divide the userNum by 2 and set it as userNum (same as typing userNum = userNum / 2;). Print the userNum

Basically, this loop will iterate until userNum becomes 1. It will keep dividing the userNum by 2 and print this value.

For the values that are smaller than 1 or even for 1, the program outputs nothing (Since the value is not greater than 1, the loop will not be executed).

You might be interested in
Universal Containers recently rolled out a Lightning Knowledge implementation; however, users are finding unreliable and unrelat
blsea [12.9K]

Answer:

Option B and option C are the correct options.

Explanation:

When they have arisen an execution the following Knowledge related to the Lightning then, the users will find incredible and that Knowledge which is not related to the Articles for showing on the Salesforce Console's Knowledge One widget.

So, the following actions that are recommended to the consultant for checking the lack of quality are.

  • Firstly, they have to activate and customize wildcards to scan for objects.
  • Then, Establish an intuitive hierarchy for the Data Category.
7 0
2 years ago
Ted knows that macros can be helpful to him in his work with Excel spreadsheets,but he also knows they have their hazards,so he
laila [671]

Answer:

Hhhhhhhhjjjffhkvs4hjtth

Explanation:

H*jhfujttjhfhjfhhdtjdgndrjgr7kvykngimg6

3 0
2 years ago
Which of the following statements does not contain an error?
Drupady [299]
III is correct .... esc code use \
3 0
2 years ago
5.11 Of these two types of programs:a. I/O-boundb. CPU-boundwhich is more likely to have voluntary context switches, and which i
Leno4ka [110]

Answer:

The answer is "both voluntary and non-voluntary context switch".

Explanation:

The description to this question can be described as follows:

Whenever processing requires resource for participant contextual switch, it is used if it is more in the situation of I/O tied. In which semi-voluntary background change can be used when time slice ends or even when processes of greater priority enter.

  • In option a, It requires voluntary context switches in I /O bound.
  • In option b, it requires a non-voluntary context switch for CPU bound.
7 0
2 years ago
Write a function called sum_scores. It should take four arguments, where each argument is the team's score for that quarter. It
saw5 [17]

Answer:

Here is the Python program which has a function sum_scores:

def sum_scores(score1, score2, score3, score4):

   sum = score1 + score2 + score3 + score4

   print(sum)    

sum_scores(14,7,3,0)

Explanation:

  • Method sum_scores takes four arguments, score1, score2, score3, score4.
  • The sum variable adds these four scores and stores the value of their addition.
  • Lastly print statement is used to print the value stored in sum variable which is the value obtained by adding the four scores.
  • Last statement calls the sum_scores method and passes four values to it which are 14,7,3,0
  • The output of the above program is:
  • 24
  • If you want to use return statement instead of print statement you can replace print(sum) with return sum. But in order to display the sum of the scores you can replace sum_scores(14,7,3,0) with print(sum_scores(14,7,3,0))
  • The program along with the output is attached as a screenshot.

5 0
2 years ago
Other questions:
  • Name and summarize the four levels of administration necessary to keep human services organization operating smoothly
    9·2 answers
  • In a particular jurisdiction, taxi fares consist of a base fare of $4.00, plus $0.25 for every 140 meters traveled. Write a func
    11·1 answer
  • Betsy recently assumed an information security role for a hospital located in the United States. What compliance regulation appl
    6·1 answer
  • C++ :Write a program that simulates flipping a coin to make decisions. The input is how many decisions are needed, and the outpu
    13·1 answer
  • 14. Emelia is very concerned about safety and has conducted a study to determine how many bike helmets were replaced at each loc
    13·2 answers
  • Write a function called st_dev. St_dev should have one #parameter, a filename. The file will contain one integer on #each line.
    7·1 answer
  • Write a program that lets a user enter N and that outputs N! (N factorial, meaning N*(N-1)*(N-2)*..\.\*2*1). Hint: Initialize a
    5·1 answer
  • Flight Simulation software, which imitates the experience of flying, is often used to train airline pilots. Which of the followi
    10·2 answers
  • 1.the following code example would print the data type of x, what data type would that be?
    12·1 answer
  • External network security threats can include management failure to support organization-wide security awareness, inadequate sec
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!