tags:

views:

50

answers:

2

here's the method:

public static int chooseStrat () 
{ 
    String[] strats = new String[1] ; 
    strats[0] = "0 - Blob" ;
    int n ;
    boolean a = false ; 
    while (a == false) ;
    {
        System.out.println ("Which strategy should the AI use?(#)") ;
        printArrayS (strats) ; 
        n = getInt () ; 
        System.out.println ("you selected "+n+"."+" are you sure you want the computer to use the "+ strats[n]+ " ?(Y/N)") ;
        String c = getIns () ;  
        while ((((!(   (c.equals ("y")) || (c.equals ("Y"))   )) && (!( (c.equals ("n")) ||  (c.equals ("N")) ) ) ))) ;
        {   
            System.out.println ("try again") ;
            c = getIns () ;
        }
        if ( (c.equals ("Y")) || (c.equals ("y")) ) 
            a = true ; 
    }
    return n ; 
} 

When i run this it never prints "Which strategy should the AI use?(#)" it just tries to get an entry from the keyboard. why does it do this?

+1  A: 

while () *;* does not do what you want, remove the semicolon.

By the way, any decent java compiler warns you about that, did you read what it told you?

Pasi Savolainen
+3  A: 
while (a == false) ;

That's an infinite loop right there. Remove the ; for starters

Matti Virkkunen
eikö uni maistu :)
Pasi Savolainen
...ei oikein maistu ei
Matti Virkkunen
Same problem on the second `while` statement too.
Kevin Brock
its not an infinate loop.
David