Pratian technologies
Company
Programming
Program
state the output of the following code:
intnum=80;
inti=1;
intmul=1;
while(i<=num){
System.out.println(i+" ");
i+=4*mul++;
if(mul%3==0)
++mul;
}
Read Solution (Total 11)
-
- i=1 prints 1
i=1+(4*1)=>5 prints 5
i=5+(4*2)=>13 prints 13
now mul value =3
enters if loop ---->increments mul to 4
i=13+(4*4)=>29 prints 29
1=29+(4*5)=>49 prints 49
now mul=6
enters the loop and increments to 7
i=49+(4*7)=>77 prints 77
exit the loop
- 9 years agoHelpfull: Yes(31) No(0)
- 1
5
13
29
49
77 - 9 years agoHelpfull: Yes(17) No(1)
- 1
5
13
25
41
61 - 9 years agoHelpfull: Yes(10) No(15)
- datatype and variable should be written seperately, i think this won't compile.
- 9 years agoHelpfull: Yes(6) No(5)
- 1
5
13
29
49
77 - 9 years agoHelpfull: Yes(3) No(0)
- As when loop start value of i= 1 and mul =1.
fistrly 1 will be printed and value of i becomes 5(i= 1+4*1). (mul ++ means post increment firstly it works then change value ). mul%3==0 this condition fails because mul = 2(as mul++) so 2%3 is not equal to zero...
the process contiues and output will be
1 5 13 29 49 77 - 7 years agoHelpfull: Yes(3) No(0)
- answer - 1,5,13,29,49,77
- 8 years agoHelpfull: Yes(0) No(0)
- 1+4+8+12+20+24+32=101(mul=4,7 are skipped bcz of ++mul)
- 7 years agoHelpfull: Yes(0) No(0)
- 1,5,13,29,77
- 7 years agoHelpfull: Yes(0) No(0)
- output::
1
5
13
29
49
77 - 7 years agoHelpfull: Yes(0) No(0)
- i | mul
1 | 1
5 | 2
13 | 4
29 | 5
49 | 7
77 | 8
109 | 10
while(i - 7 years agoHelpfull: Yes(0) No(0)
Pratian technologies Other Question
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);
optimize the code by applying the following logic.
The LCM for 2,3,4,5 and 6 is 60.This means that 61,121,181 etc. gives remainder 1, when divided by 2,3,4,5 and 6.You have to check whether 61,121,181 etc are now multipled. Display and mention the number of iterations needed to generate in the first case and last case.