新人,请大家多多关照!
import java.util.Scanner;
class dd {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("输入一个1~40的整数:");
int num = sc.nextInt();
print(num);
print1(num);
}
public static void print(int a) {
for (int i =1;i <= a ;i++ ) {
for (int j = 1;j <= 2*i-1 ;j++ ) {
if (j == 1) {
for (int m = 1;m <= a-i ;m++ ) {
System.out.print(" ");
}
}
System.out.print("*");
}
System.out.println();
}
}
public static void print1(int b) {
for (int x = b-1;x >= 1 ;x-- ) {
for (int y = 1;y <= 2*x-1 ;y++ ) {
if (y == 1) {
for (int n = 0;n <= b-1-x ;n++ ) {
System.out.print(" ");
}
}
System.out.print("*");
}
System.out.println();
}
}
}
|
|