+4 votes
1.5k views

Study the following program

//precondition: x>=0
public void demo(int x)
{
System.out.print(x % 10);
if (x % 10 != 0)
{
demo(x/10);
}
System.out.print(x%10);
}

Which of the following is printed as a result of the call demo(1234)?

1. 1441
2. 3443
3. 12344321
4. 43211234
| 1.5k views
0
it will print "4321001234" because demo(0) function call is also executing...
0
At demo(0) loop terminate by giving two zero as output.. I think so..

## 2 Answers

+6 votes

Option D

it Prints 43211234 as output

by Boss (13.7k points)
0
correct
+1

## NO. It will print 4321001234

0
yeah its 4321001234 and not 43211234.
0
It's 4321001234 but i don't know why, please explain.
0

original question is

//precondition: x>=0
public void demo(int x)
{
System.out.print(x % 10);
if (x / 10 != 0)
    {
demo(x/10);
}
System.out.print(x%10);
}
0 votes

https://ide.geeksforgeeks.org/ifEWm3t0nr

Visit this link to run and check the program.

Answer is D

by Active (3.8k points)
0
if (x%10 != 0) then o/p 4321001234

if (x/10 != 0) then o/p 43211234

Answer:

+47 votes
4 answers
1
+9 votes
3 answers
2
+5 votes
2 answers
3
+7 votes
4 answers
4
+7 votes
2 answers
5
+6 votes
3 answers
6
+4 votes
4 answers
7