嗨,即时通讯我正在用Java为Uni做游戏,但即时通讯还是很新的
import java.util.Scanner;
public class Assignment{
public static void main ( String[] args ) {
Assignment game;
game = new Assignment();
game.darkJungle();
game.oldBridge();
game.abandonedShack();
}
public void darkJungle() {
Scanner scanner = new Scanner(System.in);
System.out.println("Hello adventurer. You awake from your slumber
in a dark jungle, with no memory of your past life.");
System.out.println("");
System.out.println("Before you set off exploring for answers, what
do you wish to call yourself?");
String playerName = scanner.next();
System.out.println("hello " + playerName);
System.out.println();
System.out.println("Inventory");
System.out.println("-------------");
String weapon;
weapon = "glock";
boolean rustyKey = true;
System.out.println(weapon);
System.out.println("rustyKey");
System.out.println();
System.out.println("You look to the east and west and notice
they're the safest looking paths. Which path do you set off on?");
System.out.println("1: west");
System.out.println("2: east");
int choice;
choice = scanner.nextInt();
if(choice==1){
System.out.println("You have wandered onto a creaky old
bridge.");
scanner.nextLine();
oldBridge();}
if(choice==2)
{System.out.println("You find an abandoned shack.");
scanner.nextLine();
abandonedShack();}
}
public void oldBridge() {
System.out.println("");
System.out.println("hi");
}
public void abandonedShack() {}}
当我运行代码时,它工作正常,直到到达IF语句为止,在该语句中我可以选择输入“ 1”或“ 2”,并且结果两次显示下一个println?我对Java还是陌生的,因此将不胜感激。