Advertisement
Guest User

Untitled

a guest
May 27th, 2012
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement