【问题标题】:How do i print this Alphabets in this pattern/output : a B c D e F g H i J k L m N o P q R s T u V w X y Z [closed]我如何以这种模式/输出打印这个字母:a B c D e F g H i J k L m N o P q R s T u V w X y Z [关闭]
【发布时间】:2022-01-08 11:34:22
【问题描述】:

使用 anyloop 我将如何打印代码 像这样的大小模式:a B c D e F g H i J k L m N o P q R s T u V w X y Z

System.out.println("Aphabets In Small And Big Letter Pattern");  
// Responsible for Small Letters
for(SLet = 'a'; SLet < 'z'; SLet++){  
while(SLet%2!=0)
    {  
        System.out.print(SLet+ " ");
        SLet++;}
    }

System.out.println();
// Responsible for Big Letters
for(BLet = 'A'; BLet <= 'Z'; BLet++){  
while(BLet%2!=1)
    {  
        System.out.print(BLet+ " ");
        BLet++;}`}
    }`

    
// Combination of Small and Big Letter    

// 结果是这样的:a B c D e F g H i J k L m N o P q R s T u V w X y Z

【问题讨论】:

  • 提示:Character.toUpperCase(char ch) 也可能是Character.toLowerCase(char ch) 或代替。

标签: java loops while-loop do-while


【解决方案1】:

这段代码对我有用:(如果是偶数,写成小写)

public static void main(String[] args) {
        for (char SLet = 'A'; SLet < 'Z' + 1; SLet++) {
            char toPrint = SLet;
            if (SLet % 2 != 0)
                toPrint = Character.toLowerCase(toPrint);
            System.out.print(toPrint + " ");
        }

        System.out.println();
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-10-03
    • 2021-09-06
    • 2019-01-07
    • 1970-01-01
    • 1970-01-01
    • 2021-04-25
    • 2018-06-18
    • 1970-01-01
    相关资源
    最近更新 更多