这是方法:
public static String CPUcolor ()
{
System.out.println ("What color am I?") ;
String s = getIns() ;
System.out.println ("are you sure I'm "+s+"? (Y/N)") ;
String a = getIns() ;
while (!((a.equals ("y")) || (a.equals ("Y")) || (a.equals ("n")) || (a.equals ("N"))))
{
System.out.println ("try again") ;
a = getIns () ;
}
if (a.equals ("n") || a.equals("N"))
{CPUcolor() ;}
System.out.println ("I am "+s) ;
return s ;
}
这是此方法的可能输出(y 和 n 是用户输入):
What color am I? red are you sure I'm red? (Y/N) N What color am I? blue are you sure I'm blue? (Y/N) N What color am I? Yellow are you sure I'm Yellow? (Y/N) y I am Yellow I am blue I am red
为什么行的“我是蓝色的”和“我是红色的”打印出来?为什么它们以相反的顺序打印为红色,先输入,最后打印?