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
In an examination ,a candidates gets 4 marks for a correct answer and -1 for a wrong answer .If a candidate attempts 35 question
Phantasy [73]

Answer:

the value of x is 27

Step-by-step explanation:

ignore the next question.

7 0
3 years ago
Which of the following expressions are equal to -58? Select all that apply.
denis23 [38]
The answers are the last three equations.
7 0
3 years ago
Read 2 more answers
Megan is making bracelets to sell to earn money for the local animal shelter.it takes her 1/4 hour to pick out all the beads and
Dovator [93]
15 bracelets because 21 minutes are taken to make a bracelet and she has 315 minutes to make bracelets so divide 315 by 21 and u get 15
8 0
3 years ago
Read 2 more answers
What’s the answer to this?
IgorLugansk [536]
It’s the first one because
5 0
3 years ago
Solve for x 14 x square+7x-6
irina [24]

Answer:

x=0.450765 or x=−0.950765

Step-by-step explanation:

14x² + 7x - 6

→ Find the product, sum and factors

Product = -6

Sum = 7

Factors = No factors

→ Since there are no factors utilise the quadratic formula

\frac{-b+-\sqrt{b^{2}-4ac } }{2a}

→ List the values of a, b and c

a = 14

b = 7

c= -6

→ Substitute into the formula

\frac{-7+-\sqrt{7^{2}-4*14*-6} }{2*14}

→ Simplify

x=0.450765 or x=−0.950765

8 0
4 years ago
Read 2 more answers
Other questions:
  • Let f(x) = 3x + 2 and g(x) =7x + 6. Find f ·g and its domain.
    5·2 answers
  • Solve by completing the square.
    13·2 answers
  • You opened your first savings account 3 months ago. So far, you have earned $9.90 in simple interest, at an annual interest rate
    7·1 answer
  • Helpppp plsssss Asap!!!​
    10·1 answer
  • 44 is 55% of what number
    9·2 answers
  • Many newspapers carry a certain puzzle in which the reader must unscramble letters to form words. how many ways can the letters
    10·1 answer
  • Can somebody help a sister out ? Please help .
    10·1 answer
  • Solve the equation. 8n – 15 = 41
    13·2 answers
  • Harry wants to ride his bicycle the same of miles every day. His goal is to ride 46 miles. If he rides 4 miles each morning and
    13·1 answer
  • assume that the radius of a cylinder is the same as its height. What would happen to the volume of this cylinder if the radius w
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!