JeffGrigg

RaviShankarOjhaRefactored

Apr 28th, 2017
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 0.98 KB | None | 0 0
  1. public class RaviShankarOjhaRefactored {
  2.  
  3.     public static void main(String[] args) {
  4.         printValues(7);
  5.     }
  6.  
  7.     protected static void printValues(final int topValue) {
  8.         int topMultiplier = (topValue > 0) ? (topValue / 2 + 2) : 1;
  9.         for (int lastNumberOfLine = topValue; lastNumberOfLine >= 0; --lastNumberOfLine) {
  10.             final boolean isOdd  = (lastNumberOfLine % 2 != 0);
  11.             final boolean isZero = (lastNumberOfLine == 0);
  12.             final boolean printThisLine = (isOdd || isZero);
  13.             if (printThisLine) {
  14.                 for (int thisMultiplier = topMultiplier; thisMultiplier > 0; --thisMultiplier) {
  15.                     final int product = lastNumberOfLine * thisMultiplier;
  16.                     final int displayValue = (product == 6) ? 5 : product;
  17.                     System.out.print(displayValue + " ");
  18.                 }
  19.                 --topMultiplier;
  20.                 System.out.println();
  21.             }
  22.         }
  23.     }
  24.  
  25. }
Add Comment
Please, Sign In to add comment