+ 1

Sololearn question: please any one explain me this

long n=7654321;              long rev=0, rv=1;              do{                    long r=n % 10;                    if(r%2 > 0) rev = (rev * 10 ) + r;                         else                     System.out.println("r ="+r+(rv * r / 10));                     n=n/10;                   }while(n>0);                     System.out.println("->"+rev);

18th Jun 2020, 10:34 PM
Shaena
5 Antworten
+ 1
But the output was like 2:0 4:0 6:0 -->1003005007
19th Jun 2020, 6:25 AM
Shaena
0
Dear, was even hard to see it's really Java! Had to rewrite it for me to see what it's doing, and, this is the good news, it's really simple. The code loops over any given long / integer number to list all is uneven digits beginning with the last digit. Try it out in readable version...
18th Jun 2020, 11:36 PM
Sandra Meyer
Sandra Meyer - avatar
18th Jun 2020, 11:38 PM
Sandra Meyer
Sandra Meyer - avatar
0
It's almost the same with a few zeros 🙃 I just replaced them with some messages to see what the code is doing. My code was just to explain it.
19th Jun 2020, 12:50 PM
Sandra Meyer
Sandra Meyer - avatar
0
I've enhanced the readability a little bit, maybe it's more clear now.
19th Jun 2020, 1:54 PM
Sandra Meyer
Sandra Meyer - avatar