Why does this while terminate before recieving a value? (java)
Posted
by David
on Stack Overflow
See other posts from Stack Overflow
or by David
Published on 2010-03-26T21:20:34Z
Indexed on
2010/03/26
21:23 UTC
Read the original article
Hit count: 93
here's the relevant code snippet.
public static Territory[] assignTerri (Territory[] board, String[] colors)
{
for (int i = 0; i<board.length; i++)
{
// so a problem is that Territory.translate is void fix this.
System.out.print ("What team controls ") ; Territory.translate (i) ; System.out.println (" ?") ;
boolean a = false ;
while (a = false)
{
String s = getIns () ;
if ((checkColor (s, colors)))
{
board[i].team = (returnIndex (s, colors)) ;
a =true ;
}
else
System.out.println ("error try again") ;
}
System.out.print ("How many unites are on ") ; Territory.translate (i) ; System.out.println (" ?") ;
int n = getInt () ;
board[i].population = n ;
}
return board ;
}
as an additional piece of information, checkColor
just checks to make sure that its first argument, a string, is a string in one of the indexes of its second argument, an array.
it seems to me that when the while
the method gets a string from the keyboard and then only if that string checks out is a true and the while
allowed to terminate.
The output i get though is this:
What team controls Alaska ?
How many unites are on Alaska ?
(there is space at the end to type in an input)
This would seem to suggest that the while
terminates before an input is ever typed in since the first line of text is within the while
while the second line of text comes after it outside of it.
why is this happening?
© Stack Overflow or respective owner