all the code that is attached has been tested in both NetBeans and Eclipse on two different computers, running perfectly in Eclipse without problems.
If I write the following code everything runs correctly in both NetBeans and 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);
}
}
Output writting "hello":
Write something:
hello
text -> hello
The problem is with the following code running on NetBeans:
In this example instead of using println() we are using only 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);
}
}
Running this on NetBeans perpetually will show absolutely nothing until we write something.
Netbeans output writting "hello":
hello
Write something: text -> hello
Eclipse output writting "hello":
Write something: hello
text -> hello
Does anyone have a clue as to why and how to fix this? I don't want use Eclipse.
Using System.out.flush() does nothing to this problem.
Scanner sc = new Scanner(System.in);
System.out.print( "Write something: " );
System.out.flush();
String text = sc.nextLine();
System.out.print("text -> " + text);