Results 1 to 2 of 2
  1. #1
    adrian10288 is offline Member
    Join Date
    Nov 2011
    Rep Power

    Default Java exercise- help plese

    My question is:

    "Design, write and test a class which will read words from the keyboard until the word 'done' is entered. For each word except 'done', report whether the first character is equal to its last character. Notw that, for String str1, you can use the methods str1.charAt(0) and str1.charAt(str1.lenght()-1) to do the comparison."

    so i have this already:
    Java Code:
    import java.util.*;
    public class wordEquals {
      public static void main(String args[]) 
    	  Scanner k=new Scanner(;
    	  final String str1="done";
    	  String word;
    	  word=new String();
    		 System.out.println("Enter a word");
    	  while (word.equals(str1)==false);
    	  System.out.println("You have found the secret word!");
    and i dnt know what to do with the rest of the question. I dnt know how to use those methods mentioned in the q

    thanks all for help

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Voorschoten, the Netherlands
    Blog Entries
    Rep Power

    Default Re: Java exercise- help plese

    The assignment text already gave you (part of) the answer; there are a few more details to solve: what if the input String is empty of contains just one character? If you have made a decision for these border situations you have to implement a loop like this: (pseudo code)

    1) read a String
    2) if input == "done" then stop
    3) check the String and reply to the user
    4) go to step 1

    The details are in step 3)

    kind regards,

    Build a wall around Donald Trump; I'll pay for it.

Similar Threads

  1. get and set methods...can someone plese explain?
    By toppcon in forum New To Java
    Replies: 12
    Last Post: 07-14-2011, 04:02 AM
  2. Java exercise I REALLY need help on
    By velvetymold in forum New To Java
    Replies: 2
    Last Post: 03-27-2011, 04:02 AM
  3. Replies: 8
    Last Post: 06-24-2010, 09:59 AM
  4. Exercise for java 3d
    By armiri in forum Java 2D
    Replies: 2
    Last Post: 05-14-2010, 12:14 AM
  5. Exercise for java 3d
    By armiri in forum Java Software
    Replies: 3
    Last Post: 05-14-2010, 12:13 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts