
Untitled
By: a guest on
May 27th, 2012 | syntax:
Java | size: 0.60 KB | hits: 42 | expires: Never
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'));
}
}