java 打印空心菱形星

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java 打印空心菱形星相关的知识,希望对你有一定的参考价值。

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package BASICJAVA;

import java.util.Scanner;

/**
 *
 * @author ABIR
 */
public class Print_Hollow_Rhombus_Star {
    public static void main(String[]args){
        Scanner abir=new Scanner(System.in);
        System.out.println("Enter sample input");
        int x=abir.nextInt();
        System.out.println("sample output");
        int c=1;
        while (c<=x){
          System.out.println ();
          int d = 1;
          while (d<=(x-c)){
            System.out.print (" ");
            d++;
          }
          if (c>1){
            System.out.print ("*");
          }
          int e = 1;
          while (e<=(2*c-3)){
            System.out.print (" ");
            e++;
          }
          System.out.print ("*");
          c++;
        }
        int f = x + 1;
        int j = x - 1;
        while (f<=(2*x-1)){
          System.out.println ();
          int k = 1;
          while (k<=(f-x)){
            System.out.print (" ");
            k++;
          }
          System.out.print ("*");
          int l = 1;
          while (l<=(2*j-3)){
            System.out.print (" ");
            l++;
          }
          if (f<(2*x-1)){
            System.out.print ("*");
          }
          f++;
          j--;
        }
        System.out.println ();
        System.out.println("=======================================================");
      }
}

以上是关于java 打印空心菱形星的主要内容,如果未能解决你的问题,请参考以下文章

java 怎样写出一个菱形程序?空心和实心

用java打印菱形。

java 打印空心菱形数

java 打印空心菱形

java 空心菱形

Java 写三角形 空心三角形 菱形 空心菱形