2010-04-01 79 views
0

的方法:为什么不用这种方法打印文本?这里(JAVA)

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 ; 
} 

当我运行这个它永远不会打印“哪种策略宜采用AI(#)?”这只是尝试从键盘的输入。它为什么这样做?

+0

什么是getIns()?这是一个从键盘获取输入的函数吗? – 2010-04-01 00:24:07

+0

printArrayS,那是什么? – Ben 2010-04-01 00:24:31

回答

3

while() *;*不能做你想做的,删除分号。顺便说一下,任何像样的java编译器都会警告你,你读过它告诉你的是什么吗?

3
while (a == false) ; 

这是一个无限循环。去除 ;初学者

+0

eiköuni maistu :) – 2010-04-01 00:25:16

+0

... ei oikein maistu ei – 2010-04-01 00:26:32

+1

第二个'while'语句也是同样的问题。 – 2010-04-01 01:49:01