Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // print lines height times
- // print dash 9 twice then decrease
- // between this, print number n times (n+2)
- public class HOMEWORK{
- public static void main(String[] args){
- int height = 9; // constant
- printDesign(height);
- }
- public static void printDesign(int height){
- int numDash = 9; // initialize num of dashes as 9
- for (int i = 1; i <= height; i++){ // print height lines
- // note the line number is stored as i
- if (i < 10){ // if statement used from lines 1-9
- int prNum = i; // number which is printed
- }
- else{
- int prNum = i-10
- }
- for (int j = numDash; j >= 1; j--){ // print number of dashes
- System.out.print("-");
- }
- // print line number [ i + (i - 1) ] times
- for (int k = 1; k <= (i + (i-1)); k++){
- System.out.print(prNum);
- }
- for (int j = numDash; j >= 1; j--){ // print number of dashes
- System.out.print("-");
- }
- numDash--;
- //print new line only if i < height
- if (i < height){
- System.out.println();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement