radomes.openskiesproject.org
kallengmarium kallengmarium
  • 08-01-2017
  • Computers and Technology
Answered

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?

Verified Answer :

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

Related Questions

Which statement is true about the product of a nonzero rational number and an irrational number AThe product of a nonzero rational number and an irrational numb
what issue did the land ordinance of 1785 address
An after school job pays 4650 for 6 hours What is the unit rate
Question #2918024
What are the vast grassland areas located south of the desert and support herds and exotic animals
Duration is stable across interest ratesa Trueb False
class of 24 students 78 are allowed to attend recess on Friday how many students will be allowed to attend recess
Which of these concerns about immigration existed during the late19th century and the early21st century 2 points Immigrants contribute to unemployment among nat
A negative result of population growth is that it can cause an increase in a available labor b food production c health care costs d economic growth
This industrialist was president of the Lehigh Valley Railroad and gave donations to Lehigh University Jay Gould John Cameron Asa Packer Andrew Carnegie