Advertisement
Kancho

CODING

Feb 21st, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. Scanner key = new Scanner(System.in);
  2. System.out.println("Number: ");
  3. int num = Integer.parseInt(key.nextLine());
  4. // 1. To read tne num we mast to make it String
  5. String numToString = num + "";// make num => String
  6. int numberOfDigits = numToString.length(); // count the number of digits
  7. // number of digits is equal to number of rows
  8. for (int i = 1; i <= numberOfDigits; i++) { // numbers of rows
  9.  
  10. // 2. number of iterations is equal to each digit read reversely
  11. int iterations = Integer.parseInt(numToString.charAt(numToString.length() - i) + "");
  12. //we parsed each number from String to int and read it reversely
  13. // 3. what to print
  14. if (iterations == 0) {
  15. System.out.println("ZERO");
  16. continue;
  17. }
  18.  
  19. char whatToPrint = (char) (iterations + 33);
  20.  
  21. for (int j = 0; j < iterations; j++) {
  22. System.out.print(whatToPrint);
  23.  
  24.  
  25.  
  26. }
  27. System.out.println();
  28. }
  29.  
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement