打印如下的图形:
1.
public class Demo {
public static void main(String[] args) {
for(int i=0;i<5;i++) {
for(int j=0;j<=i;j++) {
System.out.print("*");
}
System.out.println();
}
}
}
public class Demo2 {
public static void main(String[] args) {
for(int i=0;i<5;i++) {
for (int j = 5;j>i;j--) {
System.out.print("*");
}
System.out.println();
}
}
}
public class Demo3 {
public static void main(String[] args) {
//行数 空格 星号
for (int i = 1; i <= 5; i++) {
for (int j = 0; j < 5-i; j++) {
System.out.print(" ");
}
for (int k = 0; k < i; k++) {
System.out.print("*");
}
System.out.println();
}
}
public class Demo4 {
public static void main(String[] args) {
for (int i = 1; i <= 5; i++) {
for (int j = 1; j <= i-1; j++) {
System.out.print(" ");
}
for (int k = 0;k<=5-i;k++) {
System.out.print("*");
}
System.out.println();
}
}
}
5、
public class Demo5 {
public static void main(String[] args) {
for (int i = 1; i <=4; i++) {
for (int j = 1; j <= 4-i; j++) {
System.out.print(" ");
}
for (int k = 1; k <= 2*i-1; k++) {
System.out.print("*");
}
System.out.println();
}
}
}
public class Demo6 {
public static void main(String[] args) {
for(int i=1;i<=4;i++){
for(int j=1;j<=4-i;j++){
System.out.print(" ");
}
for(int j=1;j<=i;j++){
System.out.print(j);
}
for(int k=i-1;k>=1;k--){
System.out.print(k);
}