Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class DollarFigure {
- public static void main(String[] args){
- //the outer for loop sets the number of iterations (rows)
- for(int i = 1; i <= 7; i++){
- //prints the stars furthest to the right
- for(int j = 0; j < 2 * i - 2; j++){
- System.out.print("*");
- }
- //prints the right-hand dollar signs
- for(int k = 0; k < -i + 8; k++){
- System.out.print("$");
- }
- //prints the inner stars
- for(int m = 0; m < -2 * i + 16; m++){
- System.out.print("*");
- }
- //prints the left-hand dollar signs
- for(int n = 0; n < -i + 8; n++){
- System.out.print("$");
- }
- //prints the left-hand stars
- for(int p = 0; p < 2 * i; p++){
- System.out.print("*");
- }
- System.out.println();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement