- import java.util.Scanner;
- public class dengyao2 {
- public dengyao2() {
- super();
- }
- public static void main(String[] args) {
- System.out.println("请输入菱形的边长:");
- Scanner input = new Scanner(System.in);
- if (input.hasNextInt()) {
- int a = input.nextInt();
- dengyao2 triangle = new dengyao2();
- triangle.function(a);
- } else {
- System.out.println("你输入的格式有误!请输入整数!!");
- }
- input.close();
- }
- public void function(int x) {
- for (int i = 1; i <= x; i++) {
- for (int j = 1; j <= x - i; j++) {
- System.out.print(" ");
- }
- for (int k = 1; k <= 2 * i - 1; k++) {
- System.out.print("*");
- }
- System.out.println();
- }
- for (int i = x - 1; i > 0; i--) {
- for (int j = 1; j <= x - i; j++) {
- System.out.print(" ");
- }
- for (int k = 1; k <= 2 * i - 1; k++) {
- System.out.print("*");
- }
- System.out.println();
- }
- }
- }
04-25 19:22