Results 1 to 2 of 2
Thread: Java exercise- help plese
- 11-25-2011, 03:11 PM #1
Member
- Join Date
- Nov 2011
- Posts
- 1
- Rep Power
- 0
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:
and i dnt know what to do with the rest of the question. I dnt know how to use those methods mentioned in the qJava 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!"); } }
thanks all for help
- 11-25-2011, 03:47 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,604
- Blog Entries
- 7
- Rep Power
- 17
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,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
Similar Threads
-
get and set methods...can someone plese explain?
By toppcon in forum New To JavaReplies: 12Last Post: 07-14-2011, 03:02 AM -
Java exercise I REALLY need help on
By velvetymold in forum New To JavaReplies: 2Last Post: 03-27-2011, 02:02 AM -
Could you plese explain somebody how come output of these codes.
By moonlanka in forum New To JavaReplies: 8Last Post: 06-24-2010, 08:59 AM -
Exercise for java 3d
By armiri in forum Java 2DReplies: 2Last Post: 05-13-2010, 11:14 PM -
Exercise for java 3d
By armiri in forum Java SoftwareReplies: 3Last Post: 05-13-2010, 11:13 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks