-
java利用for循环画圣诞树
package Demo;
public class Demo2 {
public static void main(String[] args) {
int[] ints={1,3,5,3,5,7,3,5,7,11,3,3,3};String result=null; String xingxing=" * "; System.out.println("圣诞树:"); for(int i=0;i<ints.length;i++){ result=""; for(int j=0;j<20-xingxing.length()*(ints[i]/2);j++){ result+=" "; } for(int j=0;j<ints[i];j++){ result+=xingxing; } result+="\n"; System.out.println(result); }
}
}