Advertisement
dimipan80

Isosceles Triangle

Aug 3rd, 2014
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.84 KB | None | 0 0
  1. // Write a program that prints an isosceles triangle of 9 copyright symbols © !
  2.  
  3. import java.util.Locale;
  4.  
  5. public class IsoscelesTriangle {
  6.  
  7.     public static void main(String[] args) {
  8.         // TODO Auto-generated method stub
  9.         Locale.setDefault(Locale.ROOT);
  10.         char copySymb = '©';
  11.         int length = 4;
  12.         System.out.printf("%s%s\n", newString(' ', length), copySymb);
  13.         int innerWidth = 1;
  14.         for (int row = 1; row < 3; row++) {
  15.             length--;
  16.             String outerSpaces = newString(' ', length);
  17.             String innerSpaces = newString(' ', innerWidth);
  18.             System.out.printf("%1$s%2$s%3$s%2$s\n", outerSpaces, copySymb, innerSpaces);
  19.             innerWidth += 2;
  20.         }
  21.  
  22.         System.out.printf("%1$s%2$s%1$s%2$s%1$s%2$s%1$s%2$s\n", ' ', copySymb);
  23.  
  24.     }
  25.  
  26.     private static String newString(char ch, int size) {
  27.         return new String(new char[size]).replace('\0', ch);
  28.     }
  29.  
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement