Results 1 to 4 of 4
- 11-25-2010, 09:48 PM #1
Member
- Join Date
- Nov 2010
- Posts
- 4
- Rep Power
- 0
how to do i make my program to do.....please help
Ask the user for a word to find in the text. Then display all the text in lower case, except for the target word, which should be in upper case. Also display how many times the target word was found.
Can someone please give me some direction on how to go about this.....thank you
- 11-25-2010, 11:26 PM #2
Member
- Join Date
- Aug 2010
- Posts
- 15
- Rep Power
- 0
various ways. i'll go over getting input, finding the number of matches, and then a way to do the uppercase thing.
for one, there are multiple ways to ask for the input. GUI-wise, you'd need to make a textfield and a button, and every time the user presses the button it searches for the word you're looking for. As for command lines, I never use them for this, but I think either System.input or System.in (Google it) works for input.
As for finding the string and counting how many times it occurs, you can either use String methods or regex.
Regex is the way to do it these days, but it seems a little daunting at first. I recommend looking up a tutorial for it online if you need a deeper understanding, but this should work:
As for the uppercase thing, use a combination of reaplceAll() and the toUpperCase() methods.Java Code:String mass = "i looked looked looked but didn't find find cats cats catsc"; //replace this string with the text you're searching through String expression = "cats"; // replace this with the text you're looking for int matches = 0; CharSequence inputStr = mass; Pattern pattern = Pattern.compile(expression); try { Matcher matcher = pattern.matcher(inputStr); while(matcher.find()){ matches++; } System.out.println(matches); }catch (Exception e) { System.out.println("no matches"); }
be sure to actually update the string when using replaceAll, too. (ex: string = string.replaceAll... (vs) string.replaceAll. just doing string.replaceAll won't update your string, but can be used within System.out.println to perform the operation and print the results with the toUpperCase results included).
good?Last edited by adhoc334; 11-25-2010 at 11:34 PM.
- 11-26-2010, 07:56 AM #3
Member
- Join Date
- Nov 2010
- Posts
- 4
- Rep Power
- 0
- 11-26-2010, 03:08 PM #4
Member
- Join Date
- Oct 2010
- Posts
- 94
- Rep Power
- 0
Hi andys,
What have you done yourself to tackle this problem? It is much appreciated at this forum to show some of your own effort. And don't be ashamed of showing bad code. You'll definitely learn from the remarks you'll get.
Hint for your problem: have a look at the indexOf methods of the String class.
Succes,
ErikI'm new to Java but I like to help where ever I can. :)
Similar Threads
-
How to make autorun program
By arshadalisoomro in forum New To JavaReplies: 1Last Post: 11-04-2010, 08:09 PM -
Help with a program ro make a landscape picture
By no s e e d s in forum New To JavaReplies: 1Last Post: 12-16-2009, 12:03 AM -
Make a program notify
By McChill in forum New To JavaReplies: 7Last Post: 06-03-2009, 09:17 PM -
Trying to make a GUI program
By GettinGwap in forum New To JavaReplies: 2Last Post: 11-04-2008, 11:37 PM -
i need help to make this program
By masaka in forum New To JavaReplies: 2Last Post: 03-23-2008, 01:26 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks