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
valentinak56 [21]
3 years ago
9

What is the result when the following code is run? double x = 1; double y = 1; int i = 0; do { y = x / 2; x = x + y; i = i + 1;

} while (x < 2.5); System.out.print(i + " ");
Mathematics
1 answer:
Mama L [17]3 years ago
6 0

Answer:

The answer is: 3

Step-by-step explanation:

1. At the begining of the program we start by declairing the variables:

 double x=1, double y=1 and int i=0.

2. The structure do...while is used to defined the loop. x<2.5 is the finalization condition of the loop. i is the counter of the loop.

y=x/2 is the first calculation

x=x+y is the second one. Here is where the values of the variable x changes.

a) for the first iteration, the values of y and x are shown below:

\\\\x=1\\y=1\\y=1/2=0.5\\x=1+0.5=1.5\\i=1

The variable x is minor to 2.5 so the loop will continue computing.

b)   the second iteration, the values of y and x are shown below::

 y=0.5\\x=1.5\\y=\frac{1.5}{2}=0.75\\ x=1.5+0.75=2.25\\i=2

The variable x is still minor to 2.5 so the loop will continue computing.

c) third iteration:

y=0.75\\x=2.25\\y=\frac{2.25}{2} =1.1125\\x=2.25+1.125=3.375\\i=3

The condition x<2.5 is not true so the loop ends.

3. System.out.print(i + " "); displays the value of the variable i wich value is 3.

Therefore the number 3 is display.

You might be interested in
How many places do you need to move the decimal to the left to write the
NikAS [45]

Answer: 6 x 10^12

Step-by-step explanation:

Move the decimal to the left so there is one non-zero digit number left of the decimal point. This will be the exponent placed on 10

3 0
2 years ago
ok so i just realised how much cartels make well then call me La Madrina lolz ok how longs a football field?
harkovskaia [24]

Answer:

100 yards or 300 feet

Step-by-step explanation:

3 0
2 years ago
Read 2 more answers
Help please ?????????
Irina18 [472]
X = -3, y = 2 rise over run
3 0
3 years ago
A singing competition is auditioning 44 contestants each hour for the next h hours, Which equation can be used to find the total
KatRina [158]
The answer is B so if you need help call me and i will help you  are welcomed 
7 0
2 years ago
A square with an area of 144cm is reduced by a factor of 1/3. How long are the new sides of the square?
denis23 [38]

Answer:

9.797. . .

Step-by-step explanation:

2/3 of 144 is 96

\sqrt{96} = 9.797...

8 0
2 years ago
Other questions:
  • 1. When a cannonball is fired, the equation of its pathway can be modeled by h = -1612 + 128t.
    8·1 answer
  • Help me with this question
    13·1 answer
  • Amswer the question in the picture
    5·1 answer
  • ∠1 ​ and ∠2 are supplementary.
    8·1 answer
  • Patanna bought some red and blue bricks. She bought a total or 100 bricks. The red bricks cost $5 each and the blue bricks cost
    14·1 answer
  • The factors of 36 that are multiples of 4
    7·2 answers
  • The volume of a sphere whose diameter is 18 centimeters is
    8·1 answer
  • The blue dot is at what value on the number line?
    7·1 answer
  • Based on the spinner shown, what is the probability of the next spin landing on a vowel?
    5·2 answers
  • Work out the percentage change when a price of £20 is decreased to £3.
    12·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!