+ 4
What is the output of these code?And how?
int a= 2; int b= 3; for(int i=3; i >1; i--) { a+=b/i; } System.out.print(a);
5 odpowiedzi
+ 8
try this :)
import java.util.*;
class Q12{
public static void main(String[] args){
int a= 2;
int b= 3;
for(int i=3; i >1; i--) {
a+=b/i;
}
System.out.print(a);
}
}
..............
yu will get 4 !
+ 4
*loop runs 2 times,
a=2 and b=3.
*1st iteration,
a=a+b/i;
a=2+3/3; \\a=2+1
so a=3.
*2nd iteration
a=3+2/2; \\since(i--) i=2
so a=4;
*condition fails(i>1) i=1
finally comes out of loop and prints 4;
+ 3
is that the letter l in the line for(int i=3; I>1; i--) {
if that is the case you get an error
+ 3
chris that is i > 3
+ 3
Nadir wadsariya the question was updated that is why I wrote that