-
Notifications
You must be signed in to change notification settings - Fork 0
/
Right_most_non_zerodigit.java
62 lines (54 loc) · 1.14 KB
/
Right_most_non_zerodigit.java
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
public class Right_most_non_zerodigit {
static int rightpastNonZeroDigit(int N, int[] A){
// code here
int s=1;
for (int i=0;i<N;i++) {
s*=A[i];
}
String n="";
String d=Integer.toString(s);
for (int i=d.length()-1;i>=0;i--) {
char c=d.charAt(i);
if(c=='0') {
n=d.substring(0,i);
}
}
String h=n.replaceAll("0", "");
if(h.length()>0) {
return h.length()+1;
}
else return -1;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
String d="230232";
if(d.contains("0")) {
System.out.println("efw");
}
}
static int rightmostNonZeroDigit(int N, int[] A){
// code here
int s=1;
for (int i=0;i<N;i++) {
s*=A[i];
}
if(s<10&s>=1){
return s;
}
String n="";
String d=Integer.toString(s);
if(!d.contains("[0]")) {
n=n+d.charAt(N-1);
int x=Integer.parseInt(n);
return x;
}
for (int i=d.length()-1;i>=1;i--) {
char c=d.charAt(i);
if(c=='0') {
n=n+d.charAt(i-1);
int x=Integer.parseInt(n);
return x;
}
}return -1;
}
}