In this program, while loop is iterated until the test expression num != 0 is evaluated to 0 (false).
Java Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | public class Main { public static void main(String[] args) { int count = 0, number = 3452; while (number != 0) { // number = number/10 number /= 10; ++count; } System.out.println("Number of digits: " + count); } } |
Output:
1 2 3 | Number of digits: 4 |