Răspuns:
package com.company;
import java.util.Scanner;
public class Digits {
public static int countNumberOfDigits(int n) {
int counter = 0;
while (n != 0) {
n /= 10;
counter++;
}
return counter;
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Introduceti un numar: ");
int num = Integer.parseInt(scanner.next());
int numberOfDigits = countNumberOfDigits(num);
for (int i = 1;i <= numberOfDigits; i++) {
System.out.printf("%.0f ",Math.floor(num / Math.pow(10,numberOfDigits - i)) % 10);
}
}
}
Explicație: