Scanner doesn't work in Blue J (java)

岁酱吖の 提交于 2019-12-11 17:55:41

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!