SHARE
TWEET

Untitled

a guest Jul 12th, 2019 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. import java.util.Scanner;
  3.  
  4.  
  5. public class HollowDiamond {
  6.         public static void main(String[] args) {
  7.         Scanner input = new Scanner(System.in);
  8.         System.out.print("Please enter a number : ");
  9.         int n = input.nextInt();
  10.         for (int row = 1; row <=n; row++) {
  11.             for (int col = 1; col <=n-row; col++) {
  12.                 System.out.print(" ");
  13.             }
  14.             for (int col = 1; col <=row; col++) {
  15.                 if(col==row){
  16.                 System.out.print("*");
  17.                 }
  18.                 else{
  19.                     System.out.print(" ");
  20.                 }
  21.                
  22.             }
  23.             for (int col = 2; col <=row; col++) {
  24.                 if(row==col){
  25.                     System.out.print("*");
  26.                 }
  27.                 else{
  28.                     System.out.print(" ");
  29.                 }
  30.             }
  31.             System.out.println("");
  32.         }
  33.     }
  34. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top