-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDigit.java
More file actions
30 lines (28 loc) · 737 Bytes
/
Digit.java
File metadata and controls
30 lines (28 loc) · 737 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
/*
Printing the digits in the given integer from
left to right order.
*/
import java.util.Scanner;
class Digit {
public static void printDigit(int x){
int temp = x;
int div = 1;
if (x<10){
return x;
}// end of base case
while(temp > 0) {
temp = temp/10;
div = div * 10;
}// end of while block
// System.out.println(div);
while(x > 0){
div = div / 10;
System.out.println(x/div);
x = x % div;
}//end of while block
}//end of printDigit
public static void main(String[] args) {
int x = 95123;
printDigit(x);
}
}// end of Digit