+ 1

How to print even numbers without using any loopin java??only in 15 lines..

26th Nov 2019, 11:10 AM
Asrar Ali
Asrar Ali - avatar
6 Answers
+ 3
Let's assume by "how" you mean logic not the code itself. Try making it by yourself for better Practice. You have to use recursive function to print even numbers without loop. Here goes the logic, create a function, check if argument is less then whatever end point you want to print upto e.g. 20, 30, 40 . . . Then check if argument variable % 2 is zero or not so you will get if it's even or odd. Print it if even else just call the function itself with argument + 1
26th Nov 2019, 11:26 AM
Raj Chhatrala
Raj Chhatrala - avatar
+ 1
Asrar Ali How you can say only in 15 lines. I think you know the logic. šŸ˜šŸ˜
26th Nov 2019, 12:05 PM
AĶ¢J
AĶ¢J - avatar
+ 1
Asrar Ali Can you show your code?
26th Nov 2019, 12:22 PM
AĶ¢J
AĶ¢J - avatar
0
Thanks bro, i try myself thanks for help
26th Nov 2019, 11:28 AM
Asrar Ali
Asrar Ali - avatar
0
Na bro i try myself but i cant
26th Nov 2019, 12:13 PM
Asrar Ali
Asrar Ali - avatar
0
This question should've tagged 'Java' instead of 'hasnain'.
26th Nov 2019, 1:59 PM
Ipang