Guest User

Untitled

a guest
Dec 11th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.  
  5. public static int pow(int cislo) {
  6. int naKolik = 1;
  7. if (cislo > 0) {
  8. for (int i = 0; i < cislo; i++) {
  9. naKolik = naKolik * 10;
  10. }
  11. }
  12. return naKolik;
  13. }
  14.  
  15. public static String premnena(String slovo) {
  16.  
  17. int cislo = Integer.parseInt(slovo);
  18. int k = 0;
  19.  
  20. while (k < slovo.length()) {
  21. for (int i = 0; i < slovo.length() / 2; i++) {
  22. if (slovo.charAt(i) < slovo.charAt(slovo.length() - (1 + i))) {
  23. cislo = cislo + (slovo.charAt(i) + 10 - slovo.charAt(slovo.length() - (1 + i))) * pow(i);
  24. } else if (slovo.charAt(i) > slovo.charAt(slovo.length() - (1 + i))) {
  25. cislo = cislo + (slovo.charAt(i) - slovo.charAt(slovo.length() - 1 - i)) * pow(i);
  26. }
  27. slovo = Integer.toString(cislo);
  28. k++;
  29. }
  30. }
  31. return slovo;
  32. }
  33.  
  34. public static void main(String[] args) {//Palidrome c.5
  35. Scanner mujScanner = new Scanner(System.in);
  36.  
  37. int kolik = mujScanner.nextInt();
  38.  
  39. while (kolik > 0) {
  40. String s = mujScanner.next();
  41. int cislo = Integer.parseInt(s) + 1;
  42. if (cislo == 9) {
  43. System.out.println("11");
  44. } else {
  45. if (cislo < 9) {
  46. System.out.println(cislo);
  47. } else {
  48. s = Integer.toString(cislo);
  49. System.out.println(premnena(s));
  50. }
  51. }
  52. kolik--;
  53. }
  54. }
  55. }
Add Comment
Please, Sign In to add comment