Calculate a+b and output the sum in standard format – that is, the digits must be separated into groups of three by commas (unless there are less than four digits).
Input Specification:
Each input file contains one test case. Each case contains a pair of integers a and b where −106 ≤a,b≤106. The numbers are separated by a space.
Output Specification:
For each test case, you should output the sum of a and b in one line. The sum must be written in the standard format.
Sample Input:
-1000000 9
Sample Output:
-999,991
import java.math.BigInteger;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner (System.in);
BigInteger a = sc.nextBigInteger();
BigInteger b = sc.nextBigInteger();
String c = a.add(b).toString();
int count = 0;
for(int i = 0 ; i < c.length(); i++) {
count++;
System.out.print(c.charAt(i));
if(c.charAt(i) == '-') continue;
if(count % 3 == c.length() % 3 && i != c.length()-1) {
System.out.print(",");
}
}
}
}