UVA 10035 Java

  1. import java.util.*;
  2. import static java.lang.System.*;
  3. public class main{
  4. public static void main(String[] args) {
  5. Scanner sc=new Scanner(System.in);
  6. while(sc.hasNextInt())
  7. {
  8. int num1 = sc.nextInt();
  9. int num2 = sc.nextInt();
  10. if(num1 == 0 && num2 ==0)
  11. break;
  12. else
  13. {
  14. int count = 0;
  15. int temp = 0;
  16. while(num1 != 0 || num2 !=0)
  17. {
  18. int n1 = num1 % 10;
  19. int n2 = num2 % 10;
  20. temp = temp + n1 + n2;
  21. if(temp >= 10)
  22. count ++;
  23. temp /= 10;
  24. num1 /= 10;
  25. num2 /= 10;
  26. }
  27. if(count == 0)
  28. System.out.println("No carry operation.");
  29. else if(count == 1)
  30. System.out.println("1 carry operation.");
  31. else
  32. System.out.println(String.format("%d carry operations.", count));
  33. }
  34. }
  35. }
  36. };

留言

這個網誌中的熱門文章

C# 井字遊戲