Created
December 25, 2017 17:39
-
-
Save SeptiyanAndika/4b95fd70ef2d67dff90d69c860960096 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * To change this license header, choose License Headers in Project Properties. | |
| * To change this template file, choose Tools | Templates | |
| * and open the template in the editor. | |
| */ | |
| /** | |
| * | |
| * @author andika | |
| */ | |
| public class test { | |
| public static void main(String[] args) { | |
| int n = 10; | |
| int j = n - 1; | |
| String pattern = Pad("", n, "xo"); | |
| for (int i = 0; i < n * 2 - 1; i++) { | |
| int maxstring = (2 * i) + 1; | |
| int padding = n - i - 1; | |
| if (i >= n) { | |
| maxstring = (2 * j) - 1; | |
| padding = n - j; | |
| j--; | |
| } | |
| String print = pattern.substring(0, maxstring); | |
| System.out.println(Pad(print, padding + print.length(), " ")); | |
| } | |
| } | |
| public static String Pad(String str, Integer length, String pattern) { | |
| if (str.length() == length) { | |
| return str; | |
| } | |
| return String.format("%" + (length - str.length()) + "s", "") | |
| .replace(" ", pattern) | |
| + str; | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
run online, http://rextester.com/QJAQT92776