Advertisement
skipter

Rhombus of Stars - Drawing with Loops/Easier way...

Apr 17th, 2017
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.70 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class Main {
  3.  
  4.     public static void main(String[] args) {
  5.  
  6.         Scanner input = new Scanner(System.in);
  7.         int n = Integer.parseInt(input.nextLine());
  8.             n--;
  9.         for (int i = 0; i <= n; i++) {
  10.             System.out.println(repeatStr(" ", (n - i)) + "*" + repeatStr(" *",i));
  11.         }
  12.         for (int i = 0; i <= n - 1; i++ ) {
  13.             System.out.println(repeatStr(" ", i + 1) + "*" + repeatStr(" *", (n - i) - 1));
  14.         }
  15.     }
  16.    public static String repeatStr(String repeatText, int counter) {
  17.         String text = "";
  18.        for (int i = 0; i < counter ; i++) {
  19.            text += repeatText;
  20.        }
  21.        return text;
  22.    }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement