|
|
|
#1
|
||||
|
||||
Anyone know Java/Object Oriented?
I'm stuck on a simple program that requires me to check two words if they are anagrams.
I know C but java..just starting out. I can read in and print to a file, no problem, do loops, etc. But I cannot break this string "FOO BAR" or "FOO OOF" into two so I can then check them. help? |
#2
|
|||
|
|||
Not much about OO in your question. I assume that you're working with java.lang.String objects. What methods are you to use, or are you to look them up and decide for yourself?
|
#3
|
||||
|
||||
methods?
no idea.. I have an idea but I cannot figure out how to code it. I think when I get that one string split into to I can call compareTo() and that will give a boolean value if they are the same or not |
#4
|
|||
|
|||
Functions in java all belong to some class, and are called methods.
You haven't defined the problem. Are you trying to split the string on spaces? If so, you can search the string for the spaces and extract substrings. Or you can use a regular expression. |
#5
|
|||
|
|||
Here's an API reference: http://download.oracle.com/javase/6/docs/api/.
java.lang.string is described here: http://download.oracle.com/javase/6/docs/api/java/lang/String.html |
#6
|
||||
|
||||
I looked up on gotapi and then a friend nudged me in the correct direction
I was using FIN.nextLine(); when I should have been using FIN.next(); that issue is solved, now to sort and compare thanks! |
#7
|
||||
|
||||
Quote:
http://www.devdaily.com/java/edu/pj/pj010006 You can do very advanced String manipulations with RegEx (Regular Expressions). Let us know if you need more direction. James
__________________
1987 Mercedes 300SDL; SOLD 1985 Mercedes 300D; SOLD 2006 Honda Pilot - wife's ride; 122K; 1995 Toyota Land Cruiser - 3X locked; 182K |
#8
|
||||
|
||||
Quote:
|
#9
|
||||
|
||||
Be careful with comparing objects such as two Strings in Java as they are objects so obj1=obj2 does not yield predicatable results you need to use .equals() method, so it should be obj1.equals(obj2).
Hope it helps - James
__________________
1987 Mercedes 300SDL; SOLD 1985 Mercedes 300D; SOLD 2006 Honda Pilot - wife's ride; 122K; 1995 Toyota Land Cruiser - 3X locked; 182K Last edited by MercFan; 02-07-2011 at 05:04 PM. |
#10
|
||||
|
||||
U have an idea for my compare. Hoping it works
|
Bookmarks |
|
|