Note that there are some explanatory texts on larger screens.

plurals
  1. POProgramming java to a symmetrical word
    primarykey
    data
    text
    <blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/11130012/programming-java-to-determine-a-symmetrical-word">Programming java to determine a symmetrical word</a> </p> </blockquote> <p>am new here, but I am having hard time figuring out how to write a code to determine an input of word and see if the first is matching with the end of the word. You may input abba and get answer it's evenly symmetric and aba is oddly symmetric.</p> <p>Please show me how:(</p> <p>Just two main things.</p> <p>first I want to know if it's oddly or evenly amount of letter(number of letter divided by 2,if it's ending with 0.5, it's oddly symmetric, if is an integer it's evenly symmetric.</p> <p>second I want to get (i.e 1=n,2=n-1,3=n-2...) position of the letter in the word to be the main idea of the execution.If there is a last letter in the oddly symmetric word, ignore the last remaining letter.</p> <p>I appreciate any headstart or idea:) Thanks!</p> <p>Thanks KDiTraglia, I made the code and compiled and here is what I put. I am not getting any further.</p> <p>Reported problem:</p> <pre><code>Exception in thread "main" java.lang.Error: Unresolved compilation problems: reverse cannot be resolved or is not a field reverse cannot be resolved or is not a field Syntax error, insert ") Statement" to complete IfStatement </code></pre> <p>This is what i got from, KDiTraglia's help</p> <pre><code> public class WordSymmetric { public static void main(String[] args) { String word = "abccdccba"; if ( (word.length() % 2) == 1 ) { System.out.println("They are oddly symmetric"); //odd } else { System.out.println("They are evenly symmetric"); //even } int halfLength = word.length() / 2; String firstHalf = word.substring(0, halfLength); String secondHalf = word.substring(halfLength, word.length()); System.out.println(secondHalf.reverse()); if (firstHalf.equals(secondHalf.reverse()) { System.out.println("They match"); //they match } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload