问题
So I have to create matrix of a certain size specified from the user. To do this I was using a Scanner and was going to take two int values, and use those to create the matrix. Long story short, when I ran it, it opened up the terminal window and said "Enter number: " just like I programmed it to, but it wouldn't let me enter a number. I investigated by making a simple program that should take in an integer and output that number, and the results were the same. Any suggestions?
import java.util.*;
public class scanner
{
public void scanner()
{
Scanner a = new Scanner(System.in);
System.out.println("Enter number: ");
int number = a.nextInt();
a.close();
System.out.print(number);
}
}
When I run this, it opens up the terminal window, says "Enter number: " but does not have the blinking cursor indicating that I can type, even when I click on it. I inserted this code into JGrasp and it worked just fine. Any help at all?
回答1:
It looks like they've made changes to their terminal in the latest release. Most likely it is a bug, and you should report it to the BlueJ maintainers (assuming you're using the latest release).
回答2:
the problem might be from having your code inside a method instead of a main method or it could just be a bug
side note though: once you type the integer for a.nextInt() and hit enter, it should set int number to that value so I don't believe that the a.close() is necessary because it will move on to printing the integer regardless
来源:https://stackoverflow.com/questions/47126927/scanner-doesnt-work-in-blue-j-java