最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

嵌套for循环字母增量

SEO心得admin43浏览0评论
本文介绍了嵌套for循环字母增量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

a

我到处搜索过,并且无法弄清楚如何在java中使用嵌套for循环创建输出。

一直持续到z

这就是我所尝试的

String alphabet =abcdefghijklmnopqrstuvwxyz ; $ p $ for(int i = 0; i <= 25; i ++) { for(char j =(char)(alphabet.charAt(i)); j

请帮我!

for(int x ='a')解决方案

; x <='z'; x ++) { for(int i ='a'; i <= x; i ++) { System.out.print (炭)ⅰ); } System.out.println(); $ p $ b $外部循环从一行切换到另一行,循环打印该特定行的字符。

I have searched everywhere and I cannot figure out how to create this output using a nested for loop in java:

"a

ab

abc

abcd"

continued until z

this is what I have tried

String alphabet = "abcdefghijklmnopqrstuvwxyz";

for(int i = 0; i <= 25; i++) { for(char j = (char)(alphabet.charAt(i)); j<=i; j++) { System.out.print(j); } System.out.println(); }

Please help me!

解决方案

Here is the answer:

for (int x = 'a'; x<='z'; x++) { for (int i = 'a'; i<=x; i++) { System.out.print((char)i); } System.out.println(); }

The outer loop switches from one row to another whilst the inner loop prints the characters for that particular row.

发布评论

评论列表(0)

  1. 暂无评论