任何想法为什么不会在用户指定的金额后启动For循环?最大数量用户可以输入为100为什么我的For循环在用户输入特定数量后继续?
class MakeTables
{
private static final int MAX_NUMBER_TABLES = 100;
public static void main(String[] args)
{
Table[] tables = new Table[MAX_NUMBER_TABLES];
int i = Integer.parseInt(JOptionPane.showInputDialog("How many tables would you like to create?"));
for (i = 0; i < tables.length; i++)
{
tables[i] = new Table();
tables[i].setHeight(Double.parseDouble(JOptionPane.showInputDialog("Enter height:")));
tables[i].setWeight(Double.parseDouble(JOptionPane.showInputDialog("Enter weight:")));
tables[i].setColor(JOptionPane.showInputDialog("Enter color:"));
tables[i].setNumberOfLegs(Integer.parseInt(JOptionPane.showInputDialog("Enter number of legs:")));
if (tables[i] != null)
JOptionPane.showMessageDialog(null,(tables[i].toString()));
} // end for
} // end main
} // end class
你问用户的价值'我',然后将其设置为0.这是什么意思? –
_for循环踢出_这甚至意味着什么? –
想必用户只想循环多次,因为用户想要表格。如果表格数组首先被初始化为具有正确的长度,这将被解决。 –