так вот мой код.Else without if error
public static void play(Player player) {
Scanner localScanner = new Scanner(System.in);
while(localScanner.hasNextLine()){
String input = localScanner.nextLine();
if(input.equals("quit")) {
System.out.println("Game over, Good bye.");
return;
}
if(input.contains("north")){
buildWorld(player, player.moveTo().connectNorth());
} else if(input.contains("south")){
buildWorld(player, player.moveTo().connectSouth());
} else if(input.contains("east")){
buildWorld(player, player.moveTo().connectEast());
} else if(input.contains("west")){
buildWorld(player, player.moveTo().connectWest());
} else {
String contents;
if (!contents.equals(""))
System.out.println("There is:\n" + contents);
else{
System.out.println("This room is empty.");
} else if(input.startsWith("pickup")){ // <-- This is the 'orphan' else
contents = input.substring(8);
if(player.moveTo().moveTo(contents)){
Object localObject = player.connectWest(contents);
if(localObject !=null)
System.out.println("You have picked up " +localObject);
else
System.out.println("You have too much damage, Game over.");}
else {
System.out.println("There is no " +contents);
}} else if (input.startsWith("drop")){
contents=input.substring(6);
if(player.moveTo(contents))
System.out.println("you dropped " +contents);
else
System.out.println("You don't have "+ contents);
} else if(input.contains("status")){
System.out.println(player);}
else{
System.out.println("What?");}
}
}
}
Я продолжаю получать другое без ошибок, и я не знаю, как это исправить. полужирный код - это ошибка. Я работаю над этим часами, и я все еще могу, чтобы он работал. пожалуйста, пожалуйста, помогите мне.
Использование стандартного форматирования кода поможет. Ваше отступы и размещение скобок настолько случайны, что мы не можем быть уверены, не прочитав все ... –
Вы просто ** не можете ** делать 'else' -sese if' – BackSlash
Стандартное другое в основном все-таки в цепочке if-else. У вас не может быть другого - если после него. – Perception