使用双重for循环打印一个等腰三角形:
public class Test7 {
public static void main(String[] args) {
for (int i=1;i<=5;i++){
for (int k=0;k<5-i;k++){
System.out.print(" ");
}
for (int j=1;j<=2*i-1;j++){
System.out.print("@");
}
System.out.println();
}
}
}
?效果图:
?打印下面这个图型:
@ @@@ @@@@@ @@@@@@@ @@@@@ @@@ @
public class Test3 {
public static void main(String[] args) {
for (int i = 1;i<=4;i++){
for (int j =0;j<4-i;j++){
System.out.print(" ");
}
for (int k =0;k<2*i-1;k++){
System.out.print("@");
}
System.out.println();
}
for(int i=1;i<=3;i++){
for (int j=1;j<=i;j++){
System.out.print(" ");
}
for (int k=1;k<=(3-i)*2+1;k++){
System.out.print("@");
}
System.out.println();
}
}
}
?效果图:
?