Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. // print lines height times
  2. // print dash 9 twice then decrease
  3. // between this, print number n times (n+2)
  4.  
  5.  
  6. public class HOMEWORK{
  7.  
  8. public static void main(String[] args){
  9. int height = 9; // constant
  10. printDesign(height);
  11. }
  12.  
  13. public static void printDesign(int height){
  14.  
  15. int numDash = 9; // initialize num of dashes as 9
  16.  
  17. for (int i = 1; i <= height; i++){ // print height lines
  18. // note the line number is stored as i
  19. if (i < 10){ // if statement used from lines 1-9
  20. int prNum = i; // number which is printed
  21. }
  22. else{
  23. int prNum = i-10
  24. }
  25.  
  26. for (int j = numDash; j >= 1; j--){ // print number of dashes
  27. System.out.print("-");
  28.  
  29. }
  30. // print line number [ i + (i - 1) ] times
  31. for (int k = 1; k <= (i + (i-1)); k++){
  32. System.out.print(prNum);
  33.  
  34. }
  35. for (int j = numDash; j >= 1; j--){ // print number of dashes
  36. System.out.print("-");
  37. }
  38. numDash--;
  39.  
  40. //print new line only if i < height
  41. if (i < height){
  42. System.out.println();
  43. }
  44. }
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement