NetBeans 12.5 Java系统存在问题。出来打印()并从控制台读取文本
所有附带的代码都已在两台不同的计算机上的NetBeans和Eclipse中进行了测试,在Eclipse中完美运行,没有任何问题
如果我编写了以下代码,那么NetBeans和Eclipse中的所有程序都能正确运行:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println( "Write something: " );
String text = sc.nextLine();
System.out.println("text -> " + text);
}
}
输出写入“hello”:
Write something:
hello
text -> hello
问题在于NetBeans上运行的以下代码:
在本例中,我们使用的不是println(),而是print()
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print( "Write something: " );
String text = sc.nextLine();
System.out.print("text -> " + text);
}
}
在NetBeans上永远运行这个程序,在我们写东西之前,绝对不会显示任何东西
Netbeans输出写入“hello”:
hello
Write something: text -> hello
Eclipse输出写“hello”:
Write something: hello
text -> hello
有人知道为什么以及如何解决这个问题吗?我不想使用Eclipse
使用系统。出来flush()对这个问题没有任何作用
Scanner sc = new Scanner(System.in);
System.out.print( "Write something: " );
System.out.flush();
String text = sc.nextLine();
System.out.print("text -> " + text);
共 (0) 个答案