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

    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(System.in);
    	  
    	  final String str1="done";
    	  
    	  String word;
    	  word=new String();
    	  
    	  do{
    		  
    		 System.out.println("Enter a word");
    		 word=k.nextLine();
    		  
    		  
    	  }
    	  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
    Location
    Voorschoten, the Netherlands
    Posts
    13,433
    Blog Entries
    7
    Rep Power
    20

    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,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

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, 03:02 AM
  2. Java exercise I REALLY need help on
    By velvetymold in forum New To Java
    Replies: 2
    Last Post: 03-27-2011, 02:02 AM
  3. Replies: 8
    Last Post: 06-24-2010, 08:59 AM
  4. Exercise for java 3d
    By armiri in forum Java 2D
    Replies: 2
    Last Post: 05-13-2010, 11:14 PM
  5. Exercise for java 3d
    By armiri in forum Java Software
    Replies: 3
    Last Post: 05-13-2010, 11:13 PM

Posting Permissions

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