UVA 10929 Java

  1. import java.util.*;
  2. public class main{
  3. public static void main(String[] args) {
  4. Scanner sc = new Scanner(System.in);
  5. while(sc.hasNextLine())
  6. {
  7. String str = sc.nextLine();
  8. if(str.equals("0"))
  9. return;
  10. int odd=0, even=0;
  11. for(int i = 0; i < str.length(); i++)
  12. {
  13. if(i % 2 == 0)
  14. //even += Integer.parseInt(String.valueOf(str.charAt(i)));
  15. even += str.charAt(i) - 48;
  16. else
  17. //odd += Integer.parseInt(String.valueOf(str.charAt(i)));
  18. odd += str.charAt(i) - 48;
  19. }
  20. if(Math.abs(odd-even)%11 == 0)
  21. System.out.println(str + " is a multiple of 11.");
  22. else
  23. System.out.println(str + " is not a multiple of 11.");
  24. }
  25. }
  26. };

留言

這個網誌中的熱門文章

C# 井字遊戲