SHARE
TWEET

Untitled

a guest May 27th, 2012 50 Never
  1. public class Diamond {
  2.  
  3.     static final String BASE = "ZYXWVUTSRQPONMLKJIHGFEDCBABCDEFGHIJKLMNOPQRSTUVWXYZ";
  4.  
  5.     public String generateDiamond(char c, char stop) {
  6.         String unmaskedLine = BASE.substring(BASE.indexOf(stop), BASE.lastIndexOf(stop) + 1);
  7.         String maskedLine = unmaskedLine.replaceAll("[^" + c + "]", " ") + "\n";
  8.  
  9.         return (c == stop) ? maskedLine : maskedLine + generateDiamond(++c, stop) + maskedLine;
  10.     }
  11.  
  12.     public static void main(String[] args) {
  13.         Diamond diamond = new Diamond();
  14.         System.out.println(diamond.generateDiamond('A', 'R'));
  15.     }
  16. }
RAW Paste Data
Top