Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on May 27th, 2012  |  syntax: Java  |  size: 0.60 KB  |  views: 49  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
This paste has a previous version, view the difference. Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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. }
clone this paste RAW Paste Data