while语句不读取(数组)对象属性

时间:2015-07-18 00:09:00

标签: java arrays object

我创建了一个对象数组(点),每个对象都有一个pointID。但是,当我输入choice1的输入时,while语句无法从对象中找到输入。例如,当我输入" point1"时,我仍然收到"请输入有效的pointID"

point[] points= new point[8];

    for (int i=0; i<8; i++)
    {
        points[i]=new point();
        String num=Integer.toString(i+1);
        points[i].pointID="point"+ num;
        points[i].x=randInt();
        points[i].y=randInt();
        points[i].z=randInt();
    }

    String choice1= JOptionPane.showInputDialog("Please enter pointID from point1 to point8:");

    while (points[0].pointID!=choice1 && points[1].pointID!=choice1 && points[2].pointID!=choice1 && points[3].pointID!=choice1 && points[4].pointID!=choice1 
        && points[5].pointID!=choice1 && points[6].pointID!=choice1 && points[7].pointID!=choice1)
    {
        JOptionPane.showMessageDialog(null,"Please enter valid pointID");
        choice1= JOptionPane.showInputDialog("Please enter pointID from point1 to point8:");

0 个答案:

没有答案