Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Diamond {
- static final String BASE = "ZYXWVUTSRQPONMLKJIHGFEDCBABCDEFGHIJKLMNOPQRSTUVWXYZ";
- public String generateDiamond(char c, char stop) {
- String unmaskedLine = BASE.substring(BASE.indexOf(stop), BASE.lastIndexOf(stop) + 1);
- String maskedLine = unmaskedLine.replaceAll("[^" + c + "]", " ") + "\n";
- return (c == stop) ? maskedLine : maskedLine + generateDiamond(++c, stop) + maskedLine;
- }
- public static void main(String[] args) {
- Diamond diamond = new Diamond();
- System.out.println(diamond.generateDiamond('A', 'R'));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement