So I'm trying to take an input from a user using Scanner(System.in) but when i try to type something into the console it won't let me.
Can anyone help?
Function.show();
Scanner input = new Scanner(System.in);
if (input.equals("a"))
{
Function.outputFile(1, list);
}
input.close();
You're forgetting to call next on the Scanner. Your if line should be if (input.next().equals("a")), instead.
I would recommend using input.next.charAt(0) in a switch...
Function.show();
Scanner input = new Scanner(System.in);
switch (input.next().charAt(0)) {
case 'a': {
Function.outputFile(1, list);
break;
}
case 'b': {
etc
}
If you separate it, (I.E. char letter) you can use switch (letter.toUpperCase()) [in theory... I've never tried it] and then you don't have to worry about case.
加载中,请稍侯......
精彩评论