Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

while loop errors

loop

  • Please log in to reply
1 reply to this topic

#1 farhanyun91

farhanyun91

    CC Regular

  • Member
  • PipPipPip
  • 46 posts

Posted 11 September 2010 - 07:05 PM

please help me out with these errors.i am freaking out and pissed off!!!
i got no idea how to resolve the errors

import javax.swing.JOptionPane;
public class TouchLight
{
    String str
    String person;
    int PersonA=1;
    int PersonB=2;
    int personC=5;
    int personD=10;
    int duration;
    int Attempt;

    Attempt=1
    str=JOptionPane.showInputDialog("Please choose your person.");
    person=String.parseString(str);

    while(Attempt<5)
        {
            if(person=PersonA && person=PersonB)
                {
                    JOptionPane.showMessageDialog(null,"Duration is"+PersonB");
                    if(duration<17)
                    {
                        {
                            JOptionPane.showMessageDialog(null,"Congratulation!!!");
                        }
                        else
                        {
                            JOptionPane.showMessageDialog(null,"Try Again!!!");
                        }
                    }
                    if(person=PersonB && person=PersonC)
                        {
                            JOptionPane.showMessageDialog(null,"Duration is"+PersonC);
                            {
                                if(duration<17)
                                {
                                    JOptionPane.showMessageDialog(null,"Congratulation");
                                }
                                else
                                {
                                    JOptionPane.showMessageDialog(null,"Try Again!!!");
                                }
                            }
                        }
                            if(person=PersonC && person=PersonD)
                                {
                                        JOptionPane.showMessageDialog(null,"Duration is"+PersonD);
                                    {
                                        if(duration<17)
                                        {
                                            JOptionPane.showMessageDialog(null,"Congratulation!!!!");
                                        }
                                        else
                                        {
                                            JOptionPane.showMessageDialog(null,"Try Again!!!!");
                                        }
                                    }
                                }

                }
                Attempt++;
                str=JOptionPane.showInputDialog("Please choose your person.");
                person=String.parseString(str);
        }




  • 0

#2 dbug

dbug

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 148 posts

Posted 11 September 2010 - 11:48 PM

Well, I see some problems in the code...

  • You cannot initialize object properties in the class declaration unless they are global and declared as static
  • You must write all your code inside one or more methods of the class. You wrote it directly inside the class declaration
  • Comparison operator is == (= is assignment operator). This will be problematic in conditional tests
  • Attempt=1 needs a semicolon after it
Also there are some strange things in your code, because this condition:

if ((person==PersonA) && (person == PersonB))
(after changing = with == and placing parenthesis to be more clear)

Will never be true because person will never be equal simultaneously to two different values.
  • 0





Also tagged with one or more of these keywords: loop

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download