Java输出一个5行的金字塔,使用for循环,且有继承的概念
1个回答
展开全部
public static void main(String[] args) {
System.out.println(printHeart("*"));
}
private static String printHeart(String input){
int[] array = {0,0,1,0,0,0,0,1,1,0,0,0,1,1,1,0};
StringBuffer sb = new StringBuffer ();
for (int i = 0;i<array.length;i++){
if(i % 3 ==0 )
sb.append("\n");
if(array[i] == 0)
sb.append(" ");
else
sb.append(" "+input);
}
return sb.toString();
}
}
System.out.println(printHeart("*"));
}
private static String printHeart(String input){
int[] array = {0,0,1,0,0,0,0,1,1,0,0,0,1,1,1,0};
StringBuffer sb = new StringBuffer ();
for (int i = 0;i<array.length;i++){
if(i % 3 ==0 )
sb.append("\n");
if(array[i] == 0)
sb.append(" ");
else
sb.append(" "+input);
}
return sb.toString();
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询