please solve this and please explain.
Attachments:
Answers
Answered by
2
Question :-
for(int i=0;i<3;I++)
{
for(int j=0;j<2;j++)
{
int number=(int)(Math.random*10);
System.out.println(number);
}
}
How many times the loop runs ?
Answer :-
The loop will run 9 times .
Explanation :-
The i-loop starts from 0 and runs till 2 .
0 , 1 , 2 and hence it runs 3 times .
The j-loop starts from 0 and runs till 1 .
0,1 and hence it runs 2 times .
Number of times the j-loop is executed = number of times the i-loop is executed × number of iterations of the j-loop .
Number of times the j-loop is executed = 2 × 3 = 6 .
Number of times the i-loop is executed = 3 .
Total number of times the loop is executed = 6 + 3 = 9 .
The answer will be 9 .
Similar questions
English,
6 months ago
Physics,
6 months ago
Math,
1 year ago
English,
1 year ago
Social Sciences,
1 year ago
Social Sciences,
1 year ago