- package com.itheima;
- import java.util.*;
- public class Demo1 {
- /*
- * 输出一个空心菱形
- */
-
- static int demo(int num){
- for(int i=0; i<num; i++){
- for(int k=num; k>i; k--){
- System.out.print(" ");
- }
-
- for(int j=0; j<=i*2; j++){
- if(j==0 || j==num)
- {
- System.out.print("*");
- }else{
- System.out.print(" ");
- }
-
- }
- System.out.println();
- }
- for(int i=0; i<num; i++){
- for(int k=0; k<=i; k++){
- System.out.print(" ");
- }
-
- for(int j=0; j<(num-i)*2-1; j++){
- if(j==0 || j==num)
- {
- System.out.print("*");
- }else{
- System.out.print(" ");
- }
-
- }
- System.out.println();
- }
- return num;
- }
-
- public static void main(String[] args) {
- Scanner in = new Scanner(System.in);
- System.out.print("请输入一个整数:");
- int num = in.nextInt();
- demo(num);
- }
- }
- //前面一个会判断 可是最后输出的*符号 不知道该恒等于几
复制代码
|
|