Advertisement
eranseg

Special Structure

Jul 30th, 2019
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.74 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class SpecStruct {
  4.     public static void main(String[] args) {
  5.         Scanner sc = new Scanner(System.in);
  6.         System.out.println("Please enter base value: ");
  7.         int base = sc.nextInt();
  8.         for(int i = 1; i <= base; i++) {
  9.             for(int j = 1; j <= i; j++) { // Loop for printing left triangle
  10.                 System.out.print("*");
  11.             }
  12.             for(int k = 0; k < (base-i)*2; k++) { // Loop for printing spaces
  13.                 System.out.print(" ");
  14.             }
  15.             for(int j = 1; j <= i; j++) { // Loop for printing right triangle
  16.                 System.out.print("*");
  17.             }
  18.             System.out.println(""); // moving to next line
  19.         }
  20.     }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement