public class PracticeLoop {
public static void main(String[] args) {
/*使用嵌套循环打印5x5的方阵
* * * * *
* * * * *
* * * * *
* * * * *
* * * * *
*/
for (int a=1;a<=5;a++){
for (int b=1;b<=5;b++) {
System.out.print("*" + "\t");
}
System.out.println();
}
/*
打印5x5的方阵
* # * # *
# * # * #
* # * # *
# * # * #
* # * # *
*/
for (int i=1;i<=5;i++){
for (int j=1;j<=5;j++) {
if((i+j)%2==0){
System.out.print("*"+"\t");
}else {
System.out.print("#" + "\t");
}
}
System.out.println();
}
}
}
使用嵌套循环打印5x5的方阵
最新推荐文章于 2022-10-18 11:00:08 发布