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
Simplify. 1/2−3(12+1)2 Enter your answer, as a simplified fraction, in the box.
lisov135 [29]

Answer: -506.5 or -253.25

Step-by-step explanation:

3 0
3 years ago
Read 2 more answers
Cual es la mitad de 5.3
Ugo [173]
La respuesta es 2.65 solamente divide 5.3/2
4 0
3 years ago
What’s the answer????
miskamm [114]
C i think is the answer
4 0
3 years ago
What is the gradient of the line<br> y = 3 - 5x?
arsen [322]
-5

u can rearrange it to be y = -5x + 3
4 0
3 years ago
Jenny bought a desk on sale for 119.60 the price was 75% less than the original price was the original price
olasank [31]

Answer:

100 - 75 = 25%

25%=119.60

need to find 1%

25/25=1%

119.60/25=1%

1%=4.784

now multiply by 100 to find original price

100% = 478.40

original price £478.40

5 0
3 years ago
Other questions:
  • Three times a number is six. What is the number ?
    6·2 answers
  • Describe and correct the error : |-13| - |13| = -13 - 13 = 26
    10·1 answer
  • Sunrise Trail is three and a quarter miles one mile equals 5280 feet what is the length in feet of the trail
    10·1 answer
  • Ten years ago 53% of American families owned stocks or stock funds. Sample data collected by the Investment Company Institute in
    12·1 answer
  • Help lol
    7·1 answer
  • What is 8/25 as a percentage?
    7·1 answer
  • What is the meassure of XYZ in the diagram below HELP ASSAP :)
    10·2 answers
  • Find the measures of the angles in ∆ABC if m∠A : m∠B : m∠C = 2:3:4.
    11·1 answer
  • Solve for x 2(3x-2)-4x+1=9 linear equations with disbribution
    10·2 answers
  • The pie is cut into 15 equal slices<br> Shade 1/5 of the pie
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!