Masrur.Mahmood
BAN USER
Comments (3)
Reputation 0
Page:
1
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
0
of 0 vote
I'm sorry, the above one is wrong. I did the answer in reverse order. Here's the correct one:
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
PrintNum(1024);
}
public void PrintNum(int n)
{
if (n == 0)
return;
PrintNum(n / 10);
System.out.println(n % 10);
}
}
Comment hidden because of low score. Click to expand.
0
of 0 vote
<pre lang="" line="1" title="CodeMonkey13867" class="run-this">class Main
{
public static void main (String[] args) throws java.lang.Exception
{
PrintNum(1024);
}
public PrintNum(int n)
{
while (n != 0)
{
System.out.println(n % 10);
n = n / 10;
}
}
}
</pre><pre title="CodeMonkey13867" input="yes">1024
</pre>
Page:
1
CareerCup is the world's biggest and best source for software engineering interview preparation. See all our resources.
See my solution below (using recursion):
- Masrur.Mahmood October 27, 2011