Computer Science, asked by nehathakare960, 9 months ago

how many times a loop will run for(int y=3;y<=30;y+=3) java​

Answers

Answered by sam3735
1

Answer:

10times

Explanation:

because 3gets added each time and it take 10 times lika 3*10=30 therefore 10times

Answered by skandabhairava
2

Answer:

The loop runs 10 times

Explanation:

We have first initialized y as 3. If the increment step was 1, the loop would have run 30 times as the condition states y should be < = 30. But the step value given here is 3...

So the program updates the variable like this :

3, 6, 9, 12, 15, 18, 21, 24, 27, 30

Its like multiplication by 3. Therefore 3 * 10 (as stated in the beginning, loop would run 10 times if step value was 1) is 30... and the loop stops right there because of the condition y<=30.

In other words... the loop updates the variable till its less than or greater than 30, and because the step value is given as 3 (y+=3), the loop is going to add 3 every time, making it a multiplication. 30 is a multiple of 3, so we know that the loops stops after the variable reaches exactly 30... and we know that 30/3 (3 here is the step size) is 10

Here u go, this is why this loop runs 10 times

I hope you understood, English is not my Primary Language

Similar questions