Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Write a program that prints an isosceles triangle of 9 copyright symbols © !
- import java.util.Locale;
- public class IsoscelesTriangle {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- Locale.setDefault(Locale.ROOT);
- char copySymb = '©';
- int length = 4;
- System.out.printf("%s%s\n", newString(' ', length), copySymb);
- int innerWidth = 1;
- for (int row = 1; row < 3; row++) {
- length--;
- String outerSpaces = newString(' ', length);
- String innerSpaces = newString(' ', innerWidth);
- System.out.printf("%1$s%2$s%3$s%2$s\n", outerSpaces, copySymb, innerSpaces);
- innerWidth += 2;
- }
- System.out.printf("%1$s%2$s%1$s%2$s%1$s%2$s%1$s%2$s\n", ' ', copySymb);
- }
- private static String newString(char ch, int size) {
- return new String(new char[size]).replace('\0', ch);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement