如何在循环中更改数组的名称 [英] How to change the name of array in a loop

查看:100
本文介绍了如何在循环中更改数组的名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好...

我想创建一个返回数组最高元素的函数...我正在尝试按如下所示绘制结构...

1
23
456
8932

上面有四个数组.我想在每个数组中进行迭代,并在每个数组中找到最高的元素,然后在屏幕上显示...

数组的数量取决于用户(即不固定为四个),用户将输入每个数组的元素,例如
(1 2,3 4,5,6 8,9,3,2),即每个数组中的元素由逗号分隔,而不同数组中的元素由空格分隔.该函数的签名为...

公共无效数组(int NumberofArrays,int ElementofArray)

我如何以上述方式输入数组的元素,以及如何根据用户输入创建数组...我会像
这样在循环中创建数组
对于()
{
int [] array = new int []
}

但是此循环将创建相同名称的数组...

谁能帮忙...

hello...

i want to create a function that returns me the highest element of arrays...i m trying to draw the structure as follows...

1
23
456
8932

Above,there are four arrays.i want to iterate in each of the array and find the highest element in each of them and display on the screen...

The number of arrays is depending on the user (i.e. not fixed to four) and the user will enter the element of each array like
(1 2,3 4,5,6 8,9,3,2) i.e the element in each array are seperated by commas and element in different array are seperated by blank spaces. The signature of the function is as...

public void Array (int NumberofArrays,int ElementofArray)

how do i enter the element of the array in the above mentioned manner and how do i create the array depending upon the user input...i m creating arrays in a loop like

for ()
{
int[] array=new int[]
}

but this loop will create the arrays of same name...

can any one help plz...

推荐答案

您的代码未标记,并且不完整.要创建用户定义大小的数组数组,您可以使用new语句创建具有指定大小的数组数组.如果不是,则需要使用列表列表.您想要一个int [] []创建一个数组数组.
Your code is not tagged, and is incomplete. To create an array of arrays of user defined size, you may be able to use the new statement to create an array of arrays with a size you specify. If not, you need to use a list of lists. You want an int[][] to create an array of arrays.


为什么不使用数组数组或数组集合
这样您就不会遇到唯一标识数组的问题.

或详细描述该过程,以便我们建议其他方法:-O
Why dont you use Array of Arrays or a collection of Arrays
Then you will not face the problem of identifying Arrays uniquely.

Or describe the process in details so that we can suggest any other approach :-O


尝试使用锯齿数组.基本语法类似于:

Try using a Jagged array. The Basic syntax is something like:

int[][] arr = new int[5][];

for (int row = 1; row <= 5; row++)
{
    arr[row - 1] = new int[row];

    for (int col = 0; col < row; col++)
    {
        arr[row - 1][col] = col + 1;
    }
}



这将创建如下结构:
1
12
123
1234
12345



This creates a structure like this:
1
12
123
1234
12345


这篇关于如何在循环中更改数组的名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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