Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 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 = 21; // constant
  10. printDesign(height);
  11. }
  12.  
  13. // public static void numOnum(int prNum){
  14. // int prNum = prNum;
  15. // }
  16. public static void printDesign(int height){
  17.  
  18. int numDash = 9; // initialize num of dashes as 9
  19. int counter = 0;
  20. int iCount = 0;
  21. for (int i = 1; i <= height; i++){ // print height lines
  22. // note the line number is stored as i
  23. int prNum = 0;
  24.  
  25. if (i < 10){ // if statement used from lines 1-9
  26. prNum = i; // number which is printed
  27.  
  28. }
  29. else{
  30. if (counter >= 5){
  31. if (icount >= 4){
  32. prNum = i -((i-5)/10*10);
  33. icount++;
  34. }
  35. }
  36. else{
  37. prNum = i -((i+5)/10*10);
  38. counter++;
  39. }
  40.  
  41.  
  42. }
  43.  
  44. for (int j = numDash; j >= 1; j--){ // print number of dashes
  45. System.out.print("-");
  46.  
  47. }
  48. // print line number [ i + (i - 1) ] times
  49. for (int k = 1; k <= (i + (i-1)); k++){
  50. System.out.print(prNum);
  51.  
  52. }
  53. for (int j = numDash; j >= 1; j--){ // print number of dashes
  54. System.out.print("-");
  55. }
  56. numDash--;
  57.  
  58. //print new line only if i < height
  59. if (i < height){
  60. System.out.println();
  61. }
  62. }
  63. }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement