-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathI001.java
49 lines (47 loc) · 984 Bytes
/
I001.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
package higherlevel;
import java.util.*;
public class I001 {
public static void main(String[] args) {
I001 pat=new I001();
Scanner s=new Scanner(System.in);
long a=s.nextLong();
long b=s.nextLong();
pat.format(a, b);
}
public void format(long a,long b) {
ArrayList list=new ArrayList();
long c=a+b;
int t=0;
if(c<0) {
c=-c;
String s=String.valueOf(c);
char m[]=s.toCharArray();
for(int i=m.length-1;i>0;i--) {
list.add(m[i]);
t++;
if(t%3==0) {
list.add(",");
}
}
list.add(m[0]);
System.out.print("-");
for(int i=list.size()-1;i>=0;i--) {
System.out.print(list.get(i));
}
}else {
String s=String.valueOf(c);
char m[]=s.toCharArray();
for(int i=m.length-1;i>0;i--) {
list.add(m[i]);
t++;
if(t%3==0) {
list.add(",");
}
}
list.add(m[0]);
for(int i=list.size()-1;i>=0;i--) {
System.out.print(list.get(i));
}
}
}
}