结构变量的Java数组

时间:2015-08-27 17:35:45

标签: java

我想创建一个结构化变量数组Process。我所拥有的就是这个例子:

int PID[];
int x[];
int y[];
int n; // no. of processes
for(int i=0;i<n;i++)
{
 System.out.println("Enter process " + (i+1) "PID=" + PID[i] );
}

如何用Java做到这一点?这是这样的吗?

class Process {
    int PID;
    int x,y;
}

我想在单.java个文件中加入我的main

2 个答案:

答案 0 :(得分:1)

如果您想要创建一个int PID[]; int x[]; int y[]; int n; // no. of processes //code that populates x[], y[] and PID[] Process[] processes = new Process[n]; for (int i = 0; i < n; i++) { processes[i] = new Process(x[i], y[i], PID[i]); } 数组并使用您的数据填充它,您可以执行以下操作:

Process

这意味着x的构造函数需要yclass Process { int PID; int x,y; public Process(int x, int y, int PID) { this.x = x; this.y = y; this.PID = PID; } } 和PID:

$currentCountry = Mage::getModel('core/store')->loadConfig('ve')->getId();
$productData = Mage::getModel('catalog/category')->load($category->getId())
                                                 ->getProductCollection()
                                                 ->setStoreId($currentCountry)
                                                 ->addAttributeToSelect('*')
                                                 ->addAttributeToFilter('status', 1)
                                                 ->addAttributeToFilter('visibility', 4);

答案 1 :(得分:-1)

Process[] process = new Process[length];

创建一个具有指定长度的Process数组。

详细了解数组的https://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html