Advertisement
KBonnicksen

Untitled

Jan 15th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.85 KB | None | 0 0
  1. public class DollarFigure {
  2.    public static void main(String[] args){
  3.  
  4.       //the outer for loop sets the number of iterations (rows)
  5.       for(int i = 1; i <= 7; i++){
  6.  
  7.          //prints the stars furthest to the right
  8.          for(int j = 0; j < 2 * i - 2; j++){
  9.             System.out.print("*");
  10.          }
  11.          //prints the right-hand dollar signs
  12.          for(int k = 0; k < -i + 8; k++){
  13.             System.out.print("$");
  14.          }
  15.          //prints the inner stars
  16.          for(int m = 0; m < -2 * i + 16; m++){
  17.             System.out.print("*");
  18.          }
  19.          //prints the left-hand dollar signs
  20.          for(int n = 0; n < -i + 8; n++){
  21.             System.out.print("$");
  22.          }
  23.          //prints the left-hand stars
  24.          for(int p = 0; p < 2 * i; p++){
  25.             System.out.print("*");
  26.          }
  27.          System.out.println();
  28.       }
  29.    }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement