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 + " ");

Answers

Answer 1
Answer:

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:

\n\nx=1\ny=1\ny=1/2=0.5\nx=1+0.5=1.5\ni=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\nx=1.5\ny=(1.5)/(2)=0.75\n x=1.5+0.75=2.25\ni=2

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

c) third iteration:

y=0.75\nx=2.25\ny=(2.25)/(2) =1.1125\nx=2.25+1.125=3.375\ni=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.


Related Questions

The number of rugby supporters at a match is 498000 correct to the nearest 1000 write down the error interval for the number of supporters at the match.
Charlie runs ata speed of 3 yards per second. about how many miles per hour does charlie run?
Please help I don't understand this
You earn $420 per week. You pay social security taxes of 7.65%, federal taxes of 22%, and state taxes of 5.95%. What is your take home pay?
What value of x will make this proportion true? 3/29 = x/116 a)11 b)12 c)15 d)16

There are 229 people attending a convention. Each table seats 8 people. What is the least number of tables needed to seat everyone?__________ tables

Answers

29 tables will be needed.

There are 5 red balls,6 white balls and 7 green balls in a box.If one ball is taken without looking,what is the probability that it is white?

Answers

5 + 6 + 7 = 18

6/18
1/3

1/3 chance
Probability = No. of favourable outcomes / no. of outcomes.
Thus,

\alpha = (6)/(13)\n \alpha = 0.46 \n \n Probability = 0.46

8=8p+13-3p
How do you solve this equation?

Answers

p = -1
8=8p+13-3p
Subtract 8p and 3p
Thats 5p
Now
8=5p + 13
Subtract 13 from 8
-5 = 5p
Divide -5 by 5
-1 = p
remember you can do anything to an equaiton as long as you do it to both sides

8=8p+13-3p
group like terms
8=8p-3p+13
add like terms
8=5p+13
minus 13 from both sides
8-13=5p+13-13
-5=5p+0
-5=5p
divide both sides by 5
-5/5=5p/5
-1=1p
-1=p
p=-1

What is the vertex of the graph of the equation y= 3x^2+6x+1

Answers

y=a(x-h)^2+k \Rightarrow \hbox{vertex}=(h,k)\ny= 3x^2+6x+1\n y=3x^2+6x+3-2\n y=3(x^2+2x+1)-2\n y=3(x+1)^2-2\Rightarrow h=-1,k=-2\n\n (-1,-2)

Can someone explain the steps to solve this so I can graph it?
y = 2x + 3?

Answers

y =mx+b   y=2x+3
m is the slope 
b is your yintercept [write it as a point   (0,b) ]
Step 1: Plot the y intercept (0,3)
Step 2: Trace slope from yintercept ... go 2 place up them 1 place right you should end up on the point (5,1)
Step 3: Draw a line through the two points

Uh, one second I got to put the picture ;-;

Answers

Answer:

92°

Step-by-step explanation: