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
you buy 7 packages total of AA and AAA. AA has 6 batteries in each pack and AAA has 8 batteries in each pack. you end up with 52
Nina [5.8K]

Answer:

you bought 8 packs in total or four of each

Step-by-step explanation:

if you ad 6 and eight you get 14 and when you divide 52 by 14 you get four. to ensure your answer if you multiply 6 by 4 and 8 by 4 and add them together you will get 52

3 0
3 years ago
EASY MATH PLEASE HELP!!
blsea [12.9K]
The answer is A. If there are 3 thirds (1/3s) per yard and there are 6 yards, 3*6=18. Because the last cut will make two 1/3-yard segments, the answer is 17 cuts and not 18.
3 0
3 years ago
Read 2 more answers
There are 10 fish in all percy tank.4 of the fish are angel fish. There are 4 more mollie fish than tetra fish. How many of each
ElenaW [278]
4 Angel fish ,4 Mollie fish and 2 tera fish
6 0
3 years ago
I have to turn this in, in 8 minutes please help​
FrozenT [24]

Answer:

20h+e

Step-by-step explanation:

e=$220

7 0
3 years ago
Determine whether the polynomial is a difference of squares and if it is, factor it.
Alexandra [31]
Just by the language difference means subtract, 

Y^2-25 is the difference of squares
factored it's the sum and difference of their square roots

(x+5) (x-5)
4 0
4 years ago
Other questions:
  • How do I solve this?
    15·1 answer
  • There are 6 runners in the 100 meter race at a track meet. in how many ways can the runners be arranged
    6·1 answer
  • Maria invests $8,000 in a bank account, which pays 9% annual interest, compounded yearly. What will be Maria's account balance a
    10·2 answers
  • Mr. Smith has an online cooking show. Before he films an episode about baking the perfect pound cake, he prepares his ingredient
    14·1 answer
  • When an exponent of a power is an even number and the base is a negative number, the value is always:
    14·2 answers
  • Determine the number of solutions that exist to the equation below. <br><br> 8(j - 4) = 2(4j - 16)
    11·1 answer
  • HELP ASAP!!! WILL MARK BRAINLIEST IF RIGHT!
    12·2 answers
  • A box shaped like a cube has an edge that is 28 cm long. How much space is available to pack inside the box?
    7·2 answers
  • The sum of 3 and c is less than or equal to -23.
    15·1 answer
  • E Homework: 3.1 Homework
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!