-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIntegertoArray.java
More file actions
44 lines (34 loc) · 972 Bytes
/
Copy pathIntegertoArray.java
File metadata and controls
44 lines (34 loc) · 972 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
40
41
42
43
44
//this will print integer to character array
//final ans will be in type char array
/*
import java.util.*;
public class IntegertoArray {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter an Integer : ");
int num = sc.nextInt();
String str = Integer.toString(num);
char[] arr = str.toCharArray();
for(int i=0;i<str.length();i++) {
System.out.println(arr[i]);
}
}
}
*/
//using charAt() - '0' method
import java.util.*;
public class IntegertoArray {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter an Integer : ");
int num = sc.nextInt();
String temp = Integer.toString(num);
int[] numarr = new int[temp.length()];
for(int i=0;i<temp.length();i++) {
numarr[i] = temp.charAt(i) - '0';
}
for(int j=0;j<temp.length();j++) {
System.out.print(numarr[j]);
}
}
}