Advertisement
cd62131

Carry

Feb 24th, 2014
372
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 0.46 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Carry {
  4.   private static int carry(long m1, long m2) {
  5.     int carry = 0, c = 0;
  6.     while (m1 != 0 || m2 != 0) {
  7.       c = (int )((m1 % 10) + (m2 % 10) + c) / 10;
  8.       carry += c;
  9.       m1 /= 10;
  10.       m2 /= 10;
  11.     }
  12.     return carry + c;
  13.   }
  14.  
  15.   public static void main(String[] args) {
  16.     Scanner in = new Scanner(System.in);
  17.     System.out.println(carry(in.nextLong(), in.nextLong()));
  18.     in.close();
  19.   }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement