0
好吧,所以我想知道是否有打印出3個字符變量的方法,這些字符變量在每種可能的組合中都會等於't'或'f'8次。我知道我可以很容易地在那裏硬編碼,但我很好奇,如果你可以用for循環來做。Java for循環打印t和f的行數爲3
好吧,所以我想知道是否有打印出3個字符變量的方法,這些字符變量在每種可能的組合中都會等於't'或'f'8次。我知道我可以很容易地在那裏硬編碼,但我很好奇,如果你可以用for循環來做。Java for循環打印t和f的行數爲3
這可能會實現
for(int i=0;i<7;i++){
if(i&1)
System.out.print("t");
else
System.out.print("f");
if(i&2)
System.out.print("t");
else
System.out.print("f");
if(i&4)
System.out.print("t");
else
System.out.print("f");
System.out.println("");
}
Char [] c={`t`,`f`};
For(char CH: c){
For(char c1: c){
For(char c2: c){
System.out.println(CH+""+c1+c2);. }}}