Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.IOException;
- import java.util.Scanner;
- /**
- * IMPORTANT:
- * O nome da classe deve ser "Main" para que a sua solução execute
- * Class name must be "Main" for your solution to execute
- * El nombre de la clase debe ser "Main" para que su solución ejecutar
- */
- public class Main {
- public static void main(String[] args) throws IOException {
- /**
- * Escreva a sua solução aqui
- * Code your solution here
- * Escriba su solución aquí
- */
- Scanner s = new Scanner(System.in);
- String s1 = "1";
- String s2 = "1";
- while(!s1.equals("0") && !s2.equals("0")) {
- s1 = s.next();
- s2 = s.next();
- if(s1.equals("0") && s2.equals("0"))
- continue;
- int v1 = converteAlgarismos(s1);
- int v2 = converteAlgarismos(s2);
- if(v1 > v2)
- System.out.println("1");
- else if(v1 < v2)
- System.out.println("2");
- else
- System.out.println("0");
- }
- }
- public static int converteAlgarismos(String n) {
- int k = 0;
- for(int i = 0; i < n.length(); i++) {
- k += Integer.parseInt(n.charAt(i)+"");
- }
- if(k >= 10) {
- return converteAlgarismos(k+"");
- }
- return k;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment