Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.13 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package pl1;
  7.  
  8. /**
  9.  *
  10.  * @author Joel
  11.  */
  12. public class EX2 {
  13.  
  14.     public static void main(String[] args) {
  15.         // TODO code application logic here}
  16.         System.out.println(palindrome(97079, 0, 6));
  17.     }
  18.  
  19.     public static int primeiroAlg(int d) {
  20.         do {
  21.             d = d / 10;
  22.         } while (d > 9);
  23.         return d;
  24.     }
  25.  
  26.     public static boolean palindrome(int numero, int i, int j) {
  27.         System.out.println(primeiroAlg(numero));
  28.         if (i < j) {
  29.             if (primeiroAlg(numero) != numero % 10) {
  30.                 return false;
  31.             }
  32.             i++;
  33.             j--;
  34.             numero = numero / 10;
  35.             numero = numero - (int) Math.pow(10, j - 2)*primeiroAlg(numero);
  36.             System.out.println("subtrair"+Math.pow(10, j - 2)*primeiroAlg(numero));
  37.             System.out.println("numero: " + numero);
  38.             palindrome(numero, i, j);
  39.         }
  40.         return true;
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement