Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Scanner key = new Scanner(System.in);
- System.out.println("Number: ");
- int num = Integer.parseInt(key.nextLine());
- // 1. To read tne num we mast to make it String
- String numToString = num + "";// make num => String
- int numberOfDigits = numToString.length(); // count the number of digits
- // number of digits is equal to number of rows
- for (int i = 1; i <= numberOfDigits; i++) { // numbers of rows
- // 2. number of iterations is equal to each digit read reversely
- int iterations = Integer.parseInt(numToString.charAt(numToString.length() - i) + "");
- //we parsed each number from String to int and read it reversely
- // 3. what to print
- if (iterations == 0) {
- System.out.println("ZERO");
- continue;
- }
- char whatToPrint = (char) (iterations + 33);
- for (int j = 0; j < iterations; j++) {
- System.out.print(whatToPrint);
- }
- System.out.println();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement