For your purposes, yes, because a loop is more simple and easier to understand (as well as a handful of other reasons around complexity).
In my experience, recursion is most powerful when you are...
Type: Posts; User: aussiemcgr
For your purposes, yes, because a loop is more simple and easier to understand (as well as a handful of other reasons around complexity).
In my experience, recursion is most powerful when you are...
A potential change to your current code (so numberEntered stays within the scope of the method):
public static int studentNumberEntered(Scanner sc) {
int numberEntered = 0;
try { ...
You are getting a stack overflow because of infinite recursion (a method calling itself forever with no exit-case). This would be occurring if your catch block is always being hit. My guess would be...
You could do what Norm said, but a potentiality "better" solution (because it does not require the creation of exceptions) would be to do something like this:
if(sc.hasNextInt()) {
int...
If you were using a GUI instead of the command prompt, there would be a handful of ways to do this.
As for preventing the program from crashing, use and if statement and the Scanner's hasNextInt()...