第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

3 個(gè) for 循環(huán)打印以下模式:

3 個(gè) for 循環(huán)打印以下模式:

白板的微信 2023-10-12 17:35:27
我侄女在學(xué)校做作業(yè)時(shí)問我這個(gè)問題,我不知道該怎么做。老師要求他們?cè)?java 中使用 3 個(gè) for 循環(huán)打印以下模式:1******12*****123****1234***12345**123456*1234567請(qǐng)幫忙。謝謝!
查看完整描述

3 回答

?
慕蓋茨4494581

TA貢獻(xiàn)1850條經(jīng)驗(yàn) 獲得超11個(gè)贊

這曾經(jīng)是我的家庭作業(yè)


代碼


for (int i = 1; i <= 7; i++) {

    for (int j = 1; j <= i; ++j) {

        System.out.print(j);

    }

    System.out.println("");

}

將會(huì)呈現(xiàn)


1

12

123

1234

12345

123456

1234567


for (int i = 1; i <= 7; i++) {

    for (int k = 7 - i; k >= 1; k--) {

        System.out.print("*");

    }

    System.out.println("");

}

將會(huì)呈現(xiàn)


******

*****

****

***

**

*

最終的


for (int i = 1; i <= 7; i++) {

    for (int j = 1; j <= i; ++j) {

        System.out.print(j);

    }

    for (int k = 7 - i; k >= 1; k--) {

        System.out.print("*");

    }

    System.out.println("");

}

將會(huì)呈現(xiàn)


1******

12*****

123****

1234***

12345**

123456*

1234567


查看完整回答
反對(duì) 回復(fù) 2023-10-12
?
回首憶惘然

TA貢獻(xiàn)1847條經(jīng)驗(yàn) 獲得超11個(gè)贊

public static void printPattern(int n) {

        for(int i=0; i<n; i++) {

            for(int k=1; k<=i+1; k++) {

                System.out.print(k);

            }

            for(int j=i+1; j<n; j++) {

                System.out.print("*");

            }

            System.out.println("");

        }

    }


查看完整回答
反對(duì) 回復(fù) 2023-10-12
?
MYYA

TA貢獻(xiàn)1868條經(jīng)驗(yàn) 獲得超4個(gè)贊

  Are you sure question has been asked to solve by using 3 for loops?

    As it is better to use less loop as much as we can. Secondly there is no requirement in problem to use third loop. you can find the desired result by using two loops:


    public class Main

    {

        public static void main(String[] args) {

               for (int i = 1; i <= 7; i++) {

                for (int j = 1; j <= 7; j++) {

                    if (j <= i) {

                            System.out.print(j);

                    }

                    else

                    {

                        System.out.print("*");

                    }

            }

                System.out.println("\n");

        }

        }

    } 


output will be:

1******

12*****

123****

1234***

12345**

123456*

1234567


查看完整回答
反對(duì) 回復(fù) 2023-10-12
  • 3 回答
  • 0 關(guān)注
  • 126 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)