ricop522

1867

Aug 12th, 2015
380
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.31 KB | None | 0 0
  1. import java.io.IOException;
  2. import java.util.Scanner;
  3.  
  4. /**
  5.  * IMPORTANT:
  6.  *      O nome da classe deve ser "Main" para que a sua solução execute
  7.  *      Class name must be "Main" for your solution to execute
  8.  *      El nombre de la clase debe ser "Main" para que su solución ejecutar
  9.  */
  10. public class Main {
  11.  
  12.     public static void main(String[] args) throws IOException {
  13.  
  14.         /**
  15.          * Escreva a sua solução aqui
  16.          * Code your solution here
  17.          * Escriba su solución aquí
  18.          */
  19.         Scanner s = new Scanner(System.in);
  20.         String s1 = "1";
  21.         String s2 = "1";
  22.         while(!s1.equals("0") && !s2.equals("0")) {        
  23.             s1 = s.next();
  24.             s2 = s.next();
  25.             if(s1.equals("0") && s2.equals("0"))
  26.                 continue;
  27.             int v1 = converteAlgarismos(s1);
  28.             int v2 = converteAlgarismos(s2);
  29.             if(v1 > v2)
  30.                 System.out.println("1");
  31.             else if(v1 < v2)
  32.                 System.out.println("2");
  33.             else
  34.                 System.out.println("0");
  35.         }
  36.     }
  37.     public static int converteAlgarismos(String n) {
  38.         int k = 0;
  39.         for(int i = 0; i < n.length(); i++) {
  40.             k += Integer.parseInt(n.charAt(i)+"");
  41.         }
  42.         if(k >= 10) {
  43.             return converteAlgarismos(k+"");
  44.         }
  45.         return k;
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment