/* 键盘录入数字输出菱形 */ import java.util.Scanner; class Exercise2 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); //创建数据录入对象 System.out.println("请输入一个数据:"); int p = sc.nextInt(); System.out.println("下面就是你要的菱形:"); for (int x = 1;x<=p ; x++) { for (int z =p;z>x ;z-- ) { System.out.print(" "); } for (int y =1;y<=x ;y++ ) { System.out.print(" *"); } System.out.println(); } for (int x = 1;x<=p ; x++) { for (int z=0; z<x;z++ ) { System.out.print(" "); } for (int y =p-1;y>x-1 ;y-- ) { System.out.print(" *"); } System.out.println(); } } } |