0

Create a recursive method that will print even numbers from the given starting numbers to ending number.

14th Nov 2019, 12:05 PM
Levi
Levi - avatar
8 Respostas
+ 1
I get it, but I'm asking you to try writing the code then see where you are making a mistake.
14th Nov 2019, 12:15 PM
Avinesh
Avinesh - avatar
+ 1
Hello Levi First If you want others to check your code to warn you of errors post your code via the plus Button (+). It's more easyer to understand what's your problem is. In your code fragment Scanner is a Class to read and write from keyboard, displays or Files. In this case you can read from System.in this is in this case the keyboard. Check this out in your main method: Scanner sc = new Scanner(System.in); while(sc.hasNext()){ System.out.print(sc.next()); } to understand how it's work. Regards kiuziu
14th Nov 2019, 2:32 PM
Kiuziu 💘 Berlin
Kiuziu 💘 Berlin - avatar
+ 1
Levi Take a look at this code https://code.sololearn.com/co2BMQetw1I4/?ref=app Regards kiuziu
14th Nov 2019, 2:38 PM
Kiuziu 💘 Berlin
Kiuziu 💘 Berlin - avatar
+ 1
Levi It's a good idea to refer Tutorials and the java Documentation Look at the oracle website: https://docs.oracle.com/en/java/javase/10/docs/api/index.html Regards kiuziu
14th Nov 2019, 2:42 PM
Kiuziu 💘 Berlin
Kiuziu 💘 Berlin - avatar
14th Nov 2019, 2:46 PM
Kiuziu 💘 Berlin
Kiuziu 💘 Berlin - avatar
0
Atleast give it a try.
14th Nov 2019, 12:11 PM
Avinesh
Avinesh - avatar
0
For example, 2 to 10 should be the output, which can be attained by using recursion.
14th Nov 2019, 12:14 PM
Levi
Levi - avatar
- 1
import java.util.*; public class Program { public static void main(String[] args) { Scanner sc = new Scanner(System.in); evenNumbers(2); } public static int evenNumbers(int even){ if(even == 0){ return 1; } else { if(even % 2 == 0){ } } } } This is the code so far. Unfortunately, I don't know what's next to do with it.
14th Nov 2019, 12:21 PM
Levi
Levi - avatar