-
-
Save folivetti/d74aac8df04a6779d1306bfb41a80d5e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.IOException; | |
import java.util.Scanner; | |
public class Main { | |
public static int inverso(int x) { | |
int y = 0; | |
while (x!=0) { | |
y = y*10 + x%10; | |
x = x/10; | |
} | |
return y; | |
} | |
public static boolean palindrome(int x) { | |
while(x%10 == 0) x/=10; | |
return inverso(x) == x; | |
} | |
public static void main(String[] args) throws IOException { | |
double R; | |
int soma, inteiro, decimais; | |
int C, casas, mult, j; | |
Scanner leitor = new Scanner(System.in); | |
C = leitor.nextInt(); | |
for (int i=0; i<C; i++) { | |
R = leitor.nextDouble(); | |
inteiro = (int)R; | |
//R = R - (int)R; | |
mult = 1; | |
while ( (R - (int)R) != 0 ){ | |
R = R*10; | |
mult = mult*10; | |
} | |
decimais = (int)R - inteiro*mult; | |
soma = inverso(inteiro) - decimais; | |
if (soma >= 0) | |
System.out.println(soma/(double)mult); | |
else | |
System.out.println(1./(double)mult); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment