3
假设我想根据计数在循环内声明一定数量的变量。是否可以根据计数在循环内声明多个变量?
private static void declaration(int amount)
{
for (int i = 0; i <= amount; i++)
{
/*Code that declares variables.
*
*When i == 0, it will declare int num0 with a value of 0.
*When i == 1, it will declare int num1 with a value of 0, etc.
*/
}
}
这是可以做到的Java内部?
是的。如果你使用一个数组。 –
您应该使用某些集合数据类型:数组或列表。 Java不允许按名称动态创建属性,如蟒蛇。 – schwobaseggl