Java nested loops

前端 未结 3 705
故里飘歌
故里飘歌 2021-01-29 14:10

Program Description:

Write a program to print 21 rows of X\'s in the shape of a large X as illustrated below. Be sure so the two rows intersect at the \

3条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-29 14:33

    You can try that:

    public class ProductX {
            public static void main(String[] args) {
            for (int i = 0; i <= 10; i++) {
                    for (int j = 0; j < 10; j++) {
                    System.out.print(" ");
                    if (i == j) {
                        System.out.print("X");
                    }
                    if(j == 9-i){
                        System.out.print("X");
                    }
                }
            System.out.println();}
    
        }
    }
    

提交回复
热议问题