Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please help in java: For all of the following words, if you move the first lette

ID: 3927004 • Letter: P

Question

Please help in java:

For all of the following words, if you move the first letter to the end of the word and then spell the word backwards , you get the original word:

banana dresser grammar potato revive uneven assess

Write a program that first asks the user how many words they will input, and then (after the user enters each word) determines whether it has this property. Treat uppercase and lowercase letters alike. That means that Banana also has this property.

This is what I have so far:

public static void main(String[] args) {

//scaner

Scanner scnr =new Scanner (System.in);

//ints

int w;

//prompt user to enter number of words

System.out.println("How many words are you going to input?");

w = scnr.nextInt();

//strings

String word;

String k = null;

String sub = null;

//loop

while (w>0){

//prompt user to enter words

System.out.println("Please enter the word(s): ");

word = scnr.next();

//ignore case

word = word.toLowerCase();

//substring

sub = word.substring(1,sub.length()+sub.charAt(0));

//for loop

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

k = k + sub.charAt(i);

}

System.out.println(k);

// if

if (k == sub){

System.out.println("This input has the property.");

}

//else

else {

System.out.println("This input doesn't have the property.");

}

  

}

  

}

}

Explanation / Answer

import java.util.Scanner;

public class stringProperty {
   public static void main(String[] args) {
       // TODO Auto-generated method stub
       int count;
       Scanner scan = new Scanner(System.in);
       System.out.print("How many string will you enter? ");
       count = scan.nextInt();
       String word,reverse_word,k;
       while(count>0)
       {
           System.out.print("Enter a string: ");
           word = scan.next();
           k = word.substring(1,word.length())+word.charAt(0);
                      
           reverse_word = "";
           for(int i=k.length()-1;i>=0;i--)
           {
               reverse_word = reverse_word + k.charAt(i);
           }
           //System.out.println(rs);
           word = word.toLowerCase();
           reverse_word = reverse_word.toLowerCase();
           if(reverse_word.equals(word))
           {
               System.out.println("The string has the property");
           }
           else
           {
               System.out.println("The string does not have the property");
           }
           count--;          
       }
   }

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote