import java.util.Scanner;
public class Main {
public static void main(String args[]) throws Exception {
Scanner scanner = new Scanner(System.in);
while (scanner.hasNext()) {
String a = scanner.nextLine();
String b = scanner.nextLine();
char[] aArr = a.toCharArray();
char[] bArr = b.toCharArray();
StringBuilder sb = new StringBuilder();
int i = aArr.length - 1;
int j = bArr.length - 1;
int count = 0;
while (i >= 0 || j >= 0) {
int temp = 0;
if (i < 0) {
temp = bArr[j--] + count - '0';
}
if (j < 0) {
temp = aArr[i--] + count - '0';
}
if (i >= 0 && j >= 0) {
temp = aArr[i--] + bArr[j--] + count - 2 * '0';
}
if (temp > 9) {
count = 1;
temp -= 10;
} else {
count = 0;
}
sb.append(temp);
if (i<0&&j<0&&count==1) {
sb.append(count);
}
}
System.out.println(sb.reverse().toString());
}
scanner.close();
}
}
java 两个很大的非负整数相加
最新推荐文章于 2022-12-30 00:15:00 发布