Java 为什么打印声明“不正确”=&燃气轮机&引用;在您输入扫描仪的输入后,请输入
我正在尝试创建一个基于文本的冒险游戏,我正在尝试添加一个功能,每当游戏需要您的输入时,在您输入的位置旁边会显示一个小记号“=>”。对于这里的代码,每当我在命令提示符(Windows7)中运行它时,就会显示输入,而小勾号不会显示。输入输入后,勾号会在输入后显示。我希望能够将记号和输入都放在一行上,就像这样,“=>[使用输入]”。请帮忙Java 为什么打印声明“不正确”=&燃气轮机&引用;在您输入扫描仪的输入后,请输入,java,input,Java,Input,我正在尝试创建一个基于文本的冒险游戏,我正在尝试添加一个功能,每当游戏需要您的输入时,在您输入的位置旁边会显示一个小记号“=>”。对于这里的代码,每当我在命令提示符(Windows7)中运行它时,就会显示输入,而小勾号不会显示。输入输入后,勾号会在输入后显示。我希望能够将记号和输入都放在一行上,就像这样,“=>[使用输入]”。请帮忙 import java.io.IOException; import java.util.Scanner; import org.fusesource.jansi
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
刷新输出流,以确保在请求输入之前写入的所有内容都已通过缓冲区。您可以使用outputstreamName.Flush()刷新输出流。有关更多帮助,请参阅或
刷新输出流将帮助您找出代码失败的地方。我该如何准确地刷新输出流?我不是要打印到文件,而是要打印到控制台。所以使用outputstreamName.flush()将不可用,对吗?不对。可以对任何缓冲输出流调用flush操作,并且应该在您希望确保缓冲区已完全处理到输出时调用flush操作。你的问题是一个很好的例子,说明了为什么你可能想这么做。