kallengmarium kallengmarium
  • 08-01-2017
  • Computers and Technology
contestada

Given the following code:

int i = 100;
int j = 10;
while (i > 0)
{
i = i / j;
j = 1 + j % 5;
}
What is the value of j after this code executes?

Respuesta :

kaevras
kaevras kaevras
  • 08-01-2017
Let's go through step by step, starting from inside the while loop.


Is i > 0? Yes. Continue.

ITERATION 1:
i now equals 10 (100 / 10)
j now equals 1 (1 + 10 % 5)

Is i > 0? Yes. Continue.

ITERATION 2:
i now equals 10 (10 / 1)
j now equals 0 (1 + 1 % 5)

Is i > 0? Yes. Continue.

ITERATION 3:
i = i / j; now generates a DivideByZeroException, thus we get a run-time error.
Answer Link

Otras preguntas

C= X+ H solve for C write the answer in the comments plz
At a certain location, the number of hours of sunlight is modeled by y = 6.4 cosine (StartFraction pi Over 26 EndFraction x) + 12 where x represents the number
When did the civilization end? (year)
which energy sources(input) cause the solar panels to generate electrical energy
The police went with the prisoner to the jail
Which tasks can Kim complete using the Customize Ribbon dialog box? Check all that apply. Rename existing ribbon tabs. Rearrange ribbon commands. Add a new main
What is the value of (x2+ y 2) + 2 when x = 4 and y = 6?
how many atoms does 2H2O have in each element, second 2 is a subscript
HURRY!! THIS ASSIGNMENT IS DUE IN 5MIN!!! THANK YOU!!!!!! A store has all board games on sale for 25% off the regular price. A checker set has a sale price of
15 Points!!! Fermentation of glucose by yeast produces A) ethyl alcohol and carbon dioxide. B) lactic acid and carbon dioxide. C) lactic acid and oxygen. D)