-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcountdigits.java
More file actions
39 lines (37 loc) · 841 Bytes
/
Copy pathcountdigits.java
File metadata and controls
39 lines (37 loc) · 841 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import java.util.Scanner;
public class countdigits
{
public static void main(String[] args)
{
Scanner scn = new Scanner(System.in);
int n = scn.nextInt();
printNumbers(n);
scn.close();
}
public static void count(int n)
{
int digit = 0;
int n1 = n;
while (n>0)
{
n = n/10;
digit++;
}
System.out.println("total no of digits are "+digit);
int div = (int) Math.pow(10, digit-1);
while (div!=0)
{
int b = n1/div;
System.out.println(b);
n1 = n1%div;
div/=10;
}
}
public static void printNumbers(int n){
if(n==0){
return;
}
printNumbers(n/10);
System.out.println(n%10);
}
}