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
vaieri [72.5K]
3 years ago
14

Help with some questions. Thank you!

Computers and Technology
1 answer:
Oksana_A [137]3 years ago
3 0

Answer:

1. E: II and III only

2. A: (int)(Math.random() * (upper − lower) ) + lower

3. A: The value of answer is N

4. E: while( !(userGuess == secretNumber) && numGuesses <= 15 )

5. C: 21

Explanation:

1. Which of the following is equivalent to while(userGuess != secretNumber)?

I. while( userGuess < secretNumber && userGuess > secretNumber)  

NO - This will test until the userGuess is smaller AND greater than the secretNumber, at the same time... so that condition will never be true.

II. while( userGuess < secretNumber || userGuess > secretNumber)

YES - This will test the value of userGuess and see if it's smaller OR greater than secetNumber.  So, it will loop until the user guesses right.

III. while( !(userGuess == secretNumber) )

YES, this will negate the match with the secretNumber.  In order words, if it's not a match, it will return true... so the loop will run until it finds a false condition (a match).

As you can see, only II and III are valid.

2.  If the lower limit were inclusive and the upper limit exclusive, which expression would properly generate values for the secret number?

A: (int)(Math.random() * (upper − lower) ) + lower

Since the lower limit is INCLUSIVE, we mustn't add one to the lower limit.  Also, the Math.random() function returns a value that matches our needs; it returns a value between [0,1[ (meaning the 0 is included, but not the 1).

Assuming the (int) caster does return only the integer portion doing a round down of the result, we'll be perfect.

3. What conclusion can be made about the state of the program when the while loop terminates?

while(!answer.equals( "N"))

{.....

A: The value of answer is N

The condition in the loops reads as "While the negation of the answer being 'N', loop".  If the answer equals 'N' then the method should return true... which will be negated by the '!' operator, causing the condition to be false. Thus we know that if the loop ends, the value of answer contains 'N', any other value will keep the loop going.

4. Assuming numGuesses is initialized to 1, how would the while statement be modified to include an extra criterion limiting the number of guesses to 15?

E: while( !(userGuess == secretNumber) && numGuesses <= 15 )

This modified condition will first test to see if the user has guessed the secretNumber (if he has, the first sub-parenthesis will be true... so the left side of the && operator will be false due to the negation operator.  The right side of the && operator will check to see how many tries have been attempted. Since the counter starts at 1, it needs to go up to 15 inclusively... so the <= is the right comparison operator.

5. After execution of the following code segment, what will be displayed?

int x = 1;

while(x < 18)

{

x += 5;

}

System.out.println(x);

C: 21

The x variable is initialized with 1... then enters the loop, in which it is incremented by 5 at each passage.

So after first passage, x = 6

After second passage, x = 11

After third passage, x = 16

After fourth passage, x = 21

Cannot enter the loop again because 21 > 18.

So, it will print out the value of 21.

You might be interested in
What are the side effects of overclocking?
Oksana_A [137]

Answer:

Reduced processor lifespan, reduced fan cooler performance over time, bugs.

Explanation:

The reason is that when you overclock your processor you are increasing its base speeds in GHZ. The processor was designed to work at a determined speed, let's say 3.00 ghz. If you increase this speed to 4.00 ghz, it's not just that now it's working faster, it also draws more power from your power supply, and increases the heat that the chip is taking. Processors are designed to endure high temperatures, therefore, you will likely not see any damaged in short term, but your components life span will be severely reduced, also depending on how much you overclock the processor, and the stability of your system, you can see bugs, unexpected restarts, and strange behavior of the computer. As an example, the i5 4670k runs at 3.80 stock speed, it can reach 50 / 65 degrees under full load. If you raise the speed up to 4.5ghz it will reach 70/80 degrees, depending on your ambient temperature and other factors.

6 0
2 years ago
Read the description of Mike’s work, and identify his profession. Mike’s job is to record sounds in a studio. He studies a video
kipiarov [429]
Mike is a Sound Engineer
7 0
2 years ago
Read 2 more answers
What key do you press so you can switch tabs quickly?
ss7ja [257]
Alt and tab to switch to open applications
4 0
3 years ago
What type of activities are performed with the help of the software used in hospitals?
faust18 [17]

Answer:

Xrays, Ultrasounds, managing patient records, communicating with colleagues, etc.

7 0
2 years ago
Read 2 more answers
1
Dimas [21]

Answer:

C.  

Explanation:

Plato users

8 0
2 years ago
Other questions:
  • The support group at Universal Containers wants agents to capture different information for product support and inquiry cases. I
    14·1 answer
  • Windows uses a graphical user interface (GUI), which means: a user can carry out commands by clicking, dragging, or otherwise ma
    6·1 answer
  • HELPPP ASAPP
    8·2 answers
  • Compare a switch to a router.
    8·2 answers
  • When you declare a string data type, you are actually creating an object from the?
    5·1 answer
  • The introduction of new information technology has a: A. dampening effect on the discourse of business ethics. B. waterfall effe
    14·1 answer
  • Can anyone fill in the space please
    6·1 answer
  • Write only in C, not C++.
    14·1 answer
  • What was original name<br> whoever answers first gets brainly crown
    9·1 answer
  • What is the name for data generated by a computer using an algorithm?
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!