What will be the output when Method(3) is invoked? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

What will be the output when Method(3) is invoked?

void Method(int c) { if(c==0) System.out.println(" "); else { System.out.println("Hello"+c); Method(--c); System.out.println(" "+c); } }

18th Dec 2019, 2:49 PM
Naman Pandey
Naman Pandey - avatar
9 Answers
+ 1
If you want explanation or reason , briefly The last Method(0) call will complete first by printing 0 by last statement. And first call Method(3) last.. If you have problem in executing, then run it playground and share link here. Then some correct your mistakes if any....
18th Dec 2019, 3:47 PM
Jayakrishna 🇮🇳
+ 2
If you want output then,Why cant run this in code play code? pls Clearly specify what you need there ? Any way the output It give as Hello3 Hello2 Hello1 0 1 2 It include spaces also as in your code...
18th Dec 2019, 3:35 PM
Jayakrishna 🇮🇳
+ 1
I said compilation error.... How can you expect output without proper details? Sry It's not possible by me. edit : √
18th Dec 2019, 3:19 PM
Jayakrishna 🇮🇳
+ 1
Read the comments there, in that program. Explanation is there. And i posted link in code comments which gives you full information.. hope that clears...
18th Dec 2019, 4:31 PM
Jayakrishna 🇮🇳
0
Its definition doesn't matter. Answer is asked of this code only,it doesn't need entire program
18th Dec 2019, 3:15 PM
Naman Pandey
Naman Pandey - avatar
0
Sorry! I have corrected the question. Answer it again.
18th Dec 2019, 3:25 PM
Naman Pandey
Naman Pandey - avatar
0
I understood 👍 I was also getting this output but I was a little bit confused. This question was asked by my computer teacher.
18th Dec 2019, 4:02 PM
Naman Pandey
Naman Pandey - avatar
0
Can you explain that Robo program that I have recently seen on your timeline
18th Dec 2019, 4:04 PM
Naman Pandey
Naman Pandey - avatar
- 1
Where is Method(3) definition? It compile error raises.. void(int c) not a proper function specification. .. what you are trying here? can you explain? edited : question √
18th Dec 2019, 3:08 PM
Jayakrishna 🇮🇳