好的,我的第一个问题搞砸了,请立即查看。
这是我的错误
java.util.NoSuchElementException
at java.util.Scanner.throwFor(Unknown Source)
at java.util.Scanner.next(Unknown Source)
at java.util.Scanner.nextByte(Unknown Source)
at java.util.Scanner.nextByte(Unknown Source)
at Filename.getMenu(Filename.java:38)
at Filename.main(Filename.java:23)
这是我的代码
import java.util.Scanner;
public class asdasdasd {
public static void main(String[] args){
short[] time = {2008, 2009};
String[] champs = {"Mouths", "Mouths"};
getMenu(time, champs);
}
public static void getMenu(short[] time, String[] champs){
Scanner keyboard = new Scanner(System.in);
byte a;
do{
System.out.println("\t\t\tMain Menu");
System.out.println("Select an Option || Example: Type '1' for Seach\n\n");
System.out.println("\t\t1.Search\n");
System.out.print("Input the number: ");
a = keyboard.nextByte();
if(a == 1){
getSearch(time, champs);
}
} while(a < 5);
keyboard.close();
}
public static void getSearch(short[] time, String[] champs){
Scanner keyboard = new Scanner(System.in);
String Team;
byte b;
do{
System.out.print("\n\nEnter the name of the team: ");
Team = keyboard.next();
if("Mouths".equals(Team) || "mouths".equals(Team)){
Team = "mouths";
}
System.out.print("Start a new Search?\nInput 1 for Yes or any other number to return to the main menu: ");
b = keyboard.nextByte();
}
while(b == 1);
keyboard.close();
}
}
好的,所以基本上输入是 1,然后是嘴巴,然后是 2。然后出现错误。
很抱歉所有愿意提供帮助的人,我没有提供太多信息。我只是害怕因为抄袭而被贬低。
我已经被告知要使用 hasNext() 或类似的东西。从来没有使用过它,我也没有任何经验。如果有人可以向我展示一个示例或如何在此编码中使用它,那就太好了。