UVA 10035 Java

import java.util.*;
import static java.lang.System.*;
public class main{
  public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    while(sc.hasNextInt())
    {
    	int num1 = sc.nextInt();
    	int num2 = sc.nextInt();
    	if(num1 == 0 && num2 ==0)
    		break;
    	else
    	{
    		int count = 0;
    		int temp = 0;
    		while(num1 != 0 || num2 !=0)
    		{
    			int n1 = num1 % 10;
    			int n2 = num2 % 10;
    			temp = temp + n1 + n2;
    			if(temp >= 10)
    				count ++;
    			temp /= 10;
    			num1 /= 10;
    			num2 /= 10;
    		}
    		if(count == 0)
    			System.out.println("No carry operation.");
    		else if(count == 1)
    			System.out.println("1 carry operation.");
    		else
    			System.out.println(String.format("%d carry operations.", count));
    	}
    }
  }
};

留言

這個網誌中的熱門文章

C# 井字遊戲