扫描输入没有存储在变量中的值 [英] Scanning for input without storing the values in a variable

查看:133
本文介绍了扫描输入没有存储在变量中的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我声明了100行和列的二维数组。林试图让用户决定了进入阵列的数字。即时应该存储值,而不将它们存储在一个变量。这是我有这么远,但我不认为这是正确的。

 公共静态无效的主要(字串[] args)
{    扫描程序扫描=新的扫描仪(System.in);
    INT [] [] NUMS =新INT [100] [100];
    INT数字;    的for(int i = 0; I< nums.length ++ I)
    {        INT [scan.nextInt()] [scan.nextInt()];    }


解决方案

嗯,首先,你正在处理一个二维数组,所以您将需要两个循环,一个用于行和其他的colums。

 的for(int i = 0; I< 100;我++)
 {
     对于(INT J = 0; J< 100; J ++)
        {
               NUMS [I] [J] = scan.nextInt();
        }
}

本语法 - INT [scan.nextInt()] [scan.nextInt(); 甚至不是合法的。

I'm declaring a 2d Array with 100 rows and columns. Im trying to get the user to dictate the numbers that go into the array. Im supposed to store the values without storing them in a variable. This is what I have so far but I don't think this is correct

 public static void main(String[] args) 
{

    Scanner scan = new Scanner(System.in);
    int [][] nums = new int[100][100];
    int digits;

    for (int i = 0; i < nums.length; ++i)
    {

        int[scan.nextInt()][scan.nextInt()];

    }

解决方案

Well, first of all, you are dealing with a two dimensional array, so you will need two loops, one for the rows and the other for the colums.

for(int i=0; i<100; i++)
 {
     for(int j=0;j<100;j++)
        {
               nums[i][j] = scan.nextInt();
        }
}

This syntax - int[scan.nextInt()][scan.nextInt()]; is not even legal.

这篇关于扫描输入没有存储在变量中的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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