java实验题a bbb ccccc ddd e怎么写
2个回答
展开全部
public class Test9 {
public static void main(String args[]) {
char index = 'a';
int length = 5;
for (int i = 0; i <= length; i++) {
if (i <= length / 2 + 1) {
for (int j = 0; j < 2 * i - 1; j++) {
System.out.print((char) (index - 1) + " ");
}
index = (char) (index + 1);
}else{
for (int j = length; j > 0; j=j-2) {
System.out.print((char) (index - 1) + " ");
}
index = (char) (index + 1);
}
}
}
}
for循环那边你可以简写写,你自己试试看,不懂再说 ,是的
public static void main(String args[]) {
char index = 'a';
int length = 5;
for (int i = 0; i <= length; i++) {
if (i <= length / 2 + 1) {
for (int j = 0; j < 2 * i - 1; j++) {
System.out.print((char) (index - 1) + " ");
}
index = (char) (index + 1);
}else{
for (int j = length; j > 0; j=j-2) {
System.out.print((char) (index - 1) + " ");
}
index = (char) (index + 1);
}
}
}
}
for循环那边你可以简写写,你自己试试看,不懂再说 ,是的
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询