This is some code I'm working on for an assignment. Say I would like to make three tables(Just a random number. The number of tables can be any number, as long as it's not over 100). Why won't the loop kick out after entering the values of the third table. Also there is a max limit set for the number of tables that can be created.
import javax.swing.JOptionPane;
class MakeTables
{
private static final int MAX_NUMBER_TABLES = 100;
public static void main(String[] args)
{
Table[] tables = new Table[MAX_NUMBER_TABLES];
for (int i = Integer.parseInt(JOptionPane.showInputDialog("How many tables would you like to create?")); i < tables.length; i++)
{
tables[i] = new Table();
if (tables[i] != null)
{
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:")));
JOptionPane.showMessageDialog(null,(tables[i].toString()));
} // end if
} // end for
} // end main
} // end class
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…