DEV Community

Beatriz Maciel
Beatriz Maciel

Posted on • Edited on

2 1

HackerRank #20 | String Reverse | 🇧🇷

Neste exercĂ­cio Ă© pedido que se verifique se uma palavra Ă© um palĂ­ndromo ou nĂŁo.
O passo a passo Ă© o seguinte:

  • Fazer o Scanner de uma palavra.
  • Declarar uma String vazia (chamei de palindromo)
  • Fazer uma iteração que começa a ler do final do tamanho (length) da String A e vai diminuindo a leitura (i--) atĂ© ler todos os caracteres
  • Somar a String vazia palindromo com os caracteres lidos da String que foi escaneada.
  • Fazer um if que iguala palindromo com a String A (escaneada). Se forem iguais retorna "Yes", caso contrário retorna "No".

=========

O cĂłdigo final fica assim, dentro da main:

        Scanner sc = new Scanner(System.in);

        System.out.println("Digite uma palavra ou frase:");
        String A = sc.nextLine();
        String palindromo = "";

        for(int i = A.length() -1; i >= 0; i--){

            palindromo += A.charAt(i);

        }

        if(palindromo.equals(A)) {
            System.out.print("Yes");
        }
        else {
            System.out.print("No");

        }
        sc.close();
Enter fullscreen mode Exit fullscreen mode

=========

ReferĂŞncias

============

Essa publicação faz parte de uma série de exercícios resolvidos em Java no HackerRank. Acesse a série completa:

Top comments (0)

Great read:

Is it Time to go Back to the Monolith?

History repeats itself. Everything old is new again and I’ve been around long enough to see ideas discarded, rediscovered and return triumphantly to overtake the fad. In recent years SQL has made a tremendous comeback from the dead. We love relational databases all over again. I think the Monolith will have its space odyssey moment again. Microservices and serverless are trends pushed by the cloud vendors, designed to sell us more cloud computing resources.

Microservices make very little sense financially for most use cases. Yes, they can ramp down. But when they scale up, they pay the costs in dividends. The increased observability costs alone line the pockets of the “big cloud” vendors.

đź‘‹ Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay