Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class Solution {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- int n = sc.nextInt();
- int spaces = n/2;
- for(int i=1;i<=(n/2)+1;i++){
- int stars = (2*i)-1;
- for(int j=1;j<=spaces;j++){
- System.out.print(" ");
- }
- spaces--;
- for(int j=1;j<=stars;j++){
- System.out.print("*");
- }
- System.out.println();
- }
- spaces = 1;
- for(int i=(n/2);i>=1;i--){
- int stars = (2*i)-1;
- for(int j=1;j<=spaces;j++){
- System.out.print(" ");
- }
- spaces++;
- for(int j=1;j<=stars;j++){
- System.out.print("*");
- }
- System.out.println();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement