0
Create a recursive method that will print even numbers from the given starting numbers to ending number.
8 Réponses
+ 1
I get it, but I'm asking you to try writing the code then see where you are making a mistake.
+ 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
+ 1
Levi
Take a look at this code
https://code.sololearn.com/co2BMQetw1I4/?ref=app
Regards kiuziu
+ 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
+ 1
Or better the API Documentation at
https://docs.oracle.com/javase/10/docs/api/index.html?overview-summary.html
0
Atleast give it a try.
0
For example, 2 to 10 should be the output, which can be attained by using recursion.
- 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.