扫描仪在Blue J中不起作用(java) [英] Scanner doesn't work in Blue J (java)

查看:96
本文介绍了扫描仪在Blue J中不起作用(java)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我必须创建用户指定的特定大小的矩阵.为此,我使用了Scanner,将采用两个int值,并使用这些值创建矩阵.长话短说,当我运行它时,它打开了终端窗口并说输入数字:",就像我对其编程一样,但是它不允许我输入数字.我通过制作一个简单的程序进行了调查,该程序应采用一个整数并输出该数字,结果是相同的.有什么建议吗?

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);
    }
}

运行此命令时,它将打开终端窗口,并显示输入数字:",但没有闪烁的光标指示我可以键入,即使单击时也是如此.我将此代码插入到JGrasp中,效果很好.有什么帮助吗?

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?

推荐答案

问题可能出在将代码放在某个方法而不是主要方法中,或者仅仅是一个错误

the problem might be from having your code inside a method instead of a main method or it could just be a bug

注意:一旦输入a.nextInt()的整数并按Enter,它应该将int数设置为该值,所以我不认为a.close()是必需的,因为它会继续前进打印整数

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

这篇关于扫描仪在Blue J中不起作用(java)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆