The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
x
+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
in Algorithms by Veteran (98.3k points) | 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:

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
49,807 questions
54,713 answers
189,263 comments
79,705 users