Basic Syntax for passing a Scanner object as a Parameter in a Function

你离开我真会死。 提交于 2019-12-04 16:52:00

You need to pass the actual variable name in when you call the method, not the class name Scanner.

getChoice(in);

instead of

getChoice(Scanner);

Incidentally, your getChoice method won't compile as shown. Just return what the scanner returns, which is an int, as you declared getChoice to return an int:

public static int getChoice(Scanner n){
    return n.nextInt();
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!