Pratian technologies
Company
Programming
Program
state the output of the following code:
longnum=11010;
long d=0;
long rem=0;
long p=1;
while(num!=0){
rem=num%10;
d=d+rem*p;
p=p*2;
num/=10;
}
System.out.println(d);
Read Solution (Total 18)
-
- simply the above logic shows us " conversion of binary to decimal number."
i.e
11010===26. - 9 years agoHelpfull: Yes(19) No(0)
- loop enters for 5 time and each time d value gets changed
d=0 p=2
d=2 p=4
d=2 p=8
d=10 p=16
finally d=10+(2*8)===>26 is the output .. and p=32 then exit the loop - 9 years agoHelpfull: Yes(7) No(0)
- n=11010 then rem=0 , d=0+0*1=0 , p=1*2 =2, num=11010/10=1101 then prints d as 0
n=1101 then rem=1 , d=0+1*2=2, p=2*2=4 ,num=1101/10=110 then prints d as 2
n=110 then rem=0 , d=2+0*4=2 , p=4*2=8, num=110/10=11 then printsn d as 2
n=11 then rem =1 , d=2+1*8=10 , p=8*2=16 ,num=11/10=1 then prinrts d as 10
n=1 then rem=1, d=10+1*16=26 , p=16*2=32 , then num=1/10 then prints d as 26
out put is: 0,2,2,10,26 - 7 years agoHelpfull: Yes(4) No(0)
- answer will be 0,2,4
- 9 years agoHelpfull: Yes(1) No(1)
- ans 16+8+2=26.
- 9 years agoHelpfull: Yes(1) No(0)
- 26 is correct answer
- 8 years agoHelpfull: Yes(1) No(2)
- 26 is absolutely correct
- 8 years agoHelpfull: Yes(1) No(1)
- The conform ans is = 26
- 7 years agoHelpfull: Yes(1) No(0)
- num | d | rem | p |
11010 | 0 | 0 | 1 |
1101 | 0 | 0 | 2 |
110 | 2 | 1 | 4 |
11 | 2 | 0 | 8 |
1 | 10 | 1 | 16 |
0 | 26 | 1 | 32 |
while()true{
rem=11010%10=0;
d=0+0*1=0
p=1*2=2
num=num/10=11010/10=1101
}
//prints 0
========================
while()true{
rem=1101%10=1;
d=0+1*2=2;
p=2*2=4;
num=1101/10=110;
//prints 2
=====================
while(num!=0)true{
rem=110%10=0;
d=2+(0*1)=2
p=4*2=8;
num=110/10=11;
}
//prints 2
=======================
while(num!=0)true{
rem=11%10=1;
d=2+(1*8)=10;
p=8*2=16;
num=11/10=1;
}
//prints 10
========================
while(num!=0)true{
rem=1%10=1;
d=10+(1*16)=26;
p=16*2=32
num=1/10=0;
}
prints 26
========================
0 2 2 10 26
===============
11010-->26
nothing but conversion of binary to decimal number. - 7 years agoHelpfull: Yes(1) No(0)
- compilation erro
- 6 years agoHelpfull: Yes(1) No(0)
- answer will be 0,2,4,6
- 9 years agoHelpfull: Yes(0) No(2)
- The value of d gets printed only after the loop is terminated and hence the final value of d gets printed i.e, 26.
- 9 years agoHelpfull: Yes(0) No(0)
- the value of d when loop get terminated is 27
- 9 years agoHelpfull: Yes(0) No(1)
- conversion of binary to decimal number
d=26
- 8 years agoHelpfull: Yes(0) No(1)
- write answer 26
- 8 years agoHelpfull: Yes(0) No(1)
- 1,2,3,4,5,6,7,8
or
change the last statement - 7 years agoHelpfull: Yes(0) No(0)
- until num(11010) equal to zero u have to continue the while loop until num equal to zero so, lastly d=26
- 7 years agoHelpfull: Yes(0) No(0)
- output::
d=26 - 7 years agoHelpfull: Yes(0) No(0)
Pratian technologies Other Question