-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDashatize it.java
More file actions
44 lines (38 loc) · 1.03 KB
/
Dashatize it.java
File metadata and controls
44 lines (38 loc) · 1.03 KB
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
package katatemplateproject;
import java.util.Arrays;
public class KataTemplateProject {
public static void main(String[] args) {
prnt(Solution.dashatize(Integer.MIN_VALUE));
}
public static <T> void prnt(T args){
System.out.println(args);
}
}
class Solution {
public static String dashatize(int num) {
if(num<1)num*=-1;
String s="";
char[] ch=Integer.toString(num).replace("-","").toCharArray();
for(int i=0;i<ch.length;i++){
if(Character.getNumericValue(ch[i])%2==0){
s+=ch[i];
}
else{
if(ch.length==1){
s+=ch[i];
}
else if(i==0){
s+=ch[i]+"-";
}
else if(i==ch.length-1){
s+="-"+ch[i];
}
else{
s+="-"+ch[i]+"-";
}
}
}
s = s.replace("--","-");
return s;
}
}