Professional Documents
Culture Documents
*;
class BigIntegerAddition {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
String num1 = sc.next();
String num2 = sc.next();
// System.out.println(digitAt("5467", 4));
// System.out.println(digitAt("5467", 5));
System.out.println(ans);
}
// 5467, 0 => 7
// 5467, 1 => 6
// 5467, 5 => 0
static int digitAt(String num, int positionStartingFromLsb) {
if (positionStartingFromLsb > num.length()-1) {
return 0;
}
// 1. String is immutable and passed by value. Which means this function cannot accept
String, but should rather use StringBuilder.
// 2. reversedSum
static void buildDigits(StringBuilder reversedNumber, int digit) {
reversedNumber.append(digit);
}
static String bigIntegerAddition(String num1, String num2) {
// TODO: Swap the numbers so that num1 > num2
int carry = 0;
StringBuilder reversedSum = new StringBuilder();
return reversedSum.reverse().toString();
}
}
// Eg: 2
// 0
// 0
// O/P: 0
// Eg: 3
// 0000
// 00
// O/P: 0
// eg: 4
// 009
// 9
// O/P: 18
// eg: 5
// 19
// 18
// 37
// eg: 6
// 99
// 99
// 198
// eg: 7
// -100
// -9
// -109
// // - Try to offload processing to functions & keeping your main code small.
// digitAt(num, i) => Returns the digit. If there is no digit that exists, it can return 0.
// Milestone 4: Prove to the interviewer that your code works with unit tests
// - Make sure you check boundary conditions