[英]Why Does The Print Statement “=>” Come after you type in Input For The Scanner
我正在嘗試創建一個基於文本的冒險游戲,我正在嘗試添加一個功能,每當游戲需要您輸入時,一個小刻號,“=>”將顯示在您輸入的位置旁邊。 使用此代碼,每當我在命令提示符(Windows 7)中運行它時,輸入顯示,而小滴答則不顯示。 輸入輸入后,勾選后會顯示。 我希望能夠將勾號和輸入全部放在一行,如“=> [使用輸入]”。 請幫忙!
import java.io.IOException;
import java.util.Scanner;
import org.fusesource.jansi.AnsiConsole;
public class Game {
public static String BLACK = "\u001B[0;30m";
public static String RED = "\u001B[0;31m";
public static String GREEN = "\u001B[0;32m";
public static String YELLOW = "\u001B[0;33m";
public static String BLUE = "\u001B[0;34m";
public static String MAGENTA = "\u001B[0;35m";
public static String CYAN = "\u001B[0;36m";
public static String WHITE = "\u001B[0;37m";
public final static String ESC = "\033[";
public static String name;
public static String gender;
public static void main(String[] args) {
AnsiConsole.systemInstall();
check();
}
public static void start() {
Scanner a = new Scanner(System.in);
System.out.println("###############################################################################");
System.out.println("# #");
System.out.println("# " + YELLOW + "^.^" + WHITE + " " + "Adventure Time Is Yes " + YELLOW + "^.^" + WHITE + " #");
System.out.println("# #");
System.out.println("###############################################################################");
//Get Name
System.out.print("\n");
System.out.println("Hello young lad! What is thy " + RED + "name " + WHITE + "you were given at birth?");
System.out.print("=> ");
//Global Variable for Name
name = a.next();
System.out.print("\n");
System.out.println("Hello " + RED + name + WHITE + "! Are you a Male or Female?");
System.out.print("=> ");
gender = a.next();
}
public static void check() {
Scanner a = new Scanner(System.in);
System.out.println("Can you see these colors?: ");
System.out.println(RED + "Red " + GREEN + "Green " + YELLOW + "Yellow " + BLUE + "Blue " + MAGENTA + "Magenta " + CYAN + "Cyan " + WHITE + "White");
System.out.println("Y/N");
System.out.print("=> ");
String as = a.nextLine();
as.toUpperCase();
if (as == "Y") {
System.out.println(ESC + "2J");
start();
} else {
System.out.println(ESC + "2J");
start();
//Future idea is to make it so there is an exact copy of the game but without color :D
}
}
}
/*try {
System.in.read();
} catch (IOException e) {
e.printStackTrace();
}
System.exit(0);*/
//System.out.println(ESC + "2J"); Clear Lines On Screen
在請求輸入之前,刷新輸出流,以確保寫入的所有內容都已通過緩沖區。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.