Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Carry {
- private static int carry(long m1, long m2) {
- int carry = 0, c = 0;
- while (m1 != 0 || m2 != 0) {
- c = (int )((m1 % 10) + (m2 % 10) + c) / 10;
- carry += c;
- m1 /= 10;
- m2 /= 10;
- }
- return carry + c;
- }
- public static void main(String[] args) {
- Scanner in = new Scanner(System.in);
- System.out.println(carry(in.nextLong(), in.nextLong()));
- in.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement