Need help w/ java class
-
Waffles
- Posts: 6876
- Joined: Mon Dec 11, 2006 3:45 am
-
sirricealot
- Posts: 841
- Joined: Sat Feb 19, 2011 3:35 pm
Need help w/ java class
int foundSymbol = password.indexOf("!);Waffles;296976 wrote:No, that will take the string as is. You will need 7 indexof statements.
int foundSymbol = password.indexOf("@);
int foundSymbol = password.indexOf("#);
int foundSymbol = password.indexOf("$);
int foundSymbol = password.indexOf("%);
int foundSymbol = password.indexOf("^);
int foundSymbol = password.indexOf("/&);
int foundSymbol = password.indexOf("*);
if(foundSymbol >=0)
Like that? Oh and I just realized I need to add equals.ignoreCase somewhere
2006 Chevy Cobalt SS/NA 2.4L IL: FEERME7
2010 Kawasaki Ninja 250r IL: RUNYON
xbxlive: sirricealot07
ps3: sirricealot7
David Runyon
2010 Kawasaki Ninja 250r IL: RUNYON
xbxlive: sirricealot07
ps3: sirricealot7
David Runyon
-
Waffles
- Posts: 6876
- Joined: Mon Dec 11, 2006 3:45 am
Need help w/ java class
Not quite that will only test the last one. You are resetting your variable each time, then only testing the last time.

-
sirricealot
- Posts: 841
- Joined: Sat Feb 19, 2011 3:35 pm
Need help w/ java class
It gave me a compile error anyways. If i have to have seperate indexOf statements for the special characters how would I go about putting those together? Obviously the !@#$%^&* wont work together as one whole string.Waffles;296979 wrote:Not quite that will only test the last one. You are resetting your variable each time, then only testing the last time.
2006 Chevy Cobalt SS/NA 2.4L IL: FEERME7
2010 Kawasaki Ninja 250r IL: RUNYON
xbxlive: sirricealot07
ps3: sirricealot7
David Runyon
2010 Kawasaki Ninja 250r IL: RUNYON
xbxlive: sirricealot07
ps3: sirricealot7
David Runyon
-
Waffles
- Posts: 6876
- Joined: Mon Dec 11, 2006 3:45 am
Need help w/ java class
Try this(my java is rusty so it might not work):
So that I am doing is setting foundSymbol to 0. If index of does not find the character in the string it returns -1. -1 + 1 = 0. Then if one of them hits in the index it will return a 1 or greater. So if foundSymbol is larger than 0 you contain one of the characters.
You also forgot the closing quotes in your string.
Code: Select all
int foundSymbol = 0
int foundSymbol = foundSymbol + password.indexOf("!") + 1;
int foundSymbol = foundSymbol + password.indexOf("@") + 1;
int foundSymbol = foundSymbol + password.indexOf("#") + 1;
int foundSymbol = foundSymbol + password.indexOf("$") + 1;
int foundSymbol = foundSymbol + password.indexOf("%") + 1;
int foundSymbol = foundSymbol + password.indexOf("^") + 1;
int foundSymbol = foundSymbol + password.indexOf("/&") + 1;
int foundSymbol = foundSymbol + password.indexOf("*") + 1;
if(foundSymbol > 0){}
You also forgot the closing quotes in your string.

-
sirricealot
- Posts: 841
- Joined: Sat Feb 19, 2011 3:35 pm
Need help w/ java class
Same error I've been getting with the multiple indexOf.Waffles;296981 wrote:Try this(my java is rusty so it might not work):So that I am doing is setting foundSymbol to 0. If index of does not find the character in the string it returns -1. -1 + 1 = 0. Then if one of them hits in the index it will return a 1 or greater. So if foundSymbol is larger than 0 you contain one of the characters.Code: Select all
int foundSymbol = 0 int foundSymbol = foundSymbol + password.indexOf("!") + 1; int foundSymbol = foundSymbol + password.indexOf("@") + 1; int foundSymbol = foundSymbol + password.indexOf("#") + 1; int foundSymbol = foundSymbol + password.indexOf("$") + 1; int foundSymbol = foundSymbol + password.indexOf("%") + 1; int foundSymbol = foundSymbol + password.indexOf("^") + 1; int foundSymbol = foundSymbol + password.indexOf("/&") + 1; int foundSymbol = foundSymbol + password.indexOf("*") + 1; if(foundSymbol > 0){}
You also forgot the closing quotes in your string.
java:45: error: variable foundSymbol is already defined in method main(String[])
but I got like 8 of those, 45 and up.
2006 Chevy Cobalt SS/NA 2.4L IL: FEERME7
2010 Kawasaki Ninja 250r IL: RUNYON
xbxlive: sirricealot07
ps3: sirricealot7
David Runyon
2010 Kawasaki Ninja 250r IL: RUNYON
xbxlive: sirricealot07
ps3: sirricealot7
David Runyon
-
sirricealot
- Posts: 841
- Joined: Sat Feb 19, 2011 3:35 pm
Need help w/ java class
After struggling and contacting the teacher numerous times I ended up submitting an assignment that didnt run and wasnt finished, i still managed to get an 80/100 though. Thanks for the help. This week he provided us with some sample code and all we have to do is add to it in order to complete the program, much easier!
2006 Chevy Cobalt SS/NA 2.4L IL: FEERME7
2010 Kawasaki Ninja 250r IL: RUNYON
xbxlive: sirricealot07
ps3: sirricealot7
David Runyon
2010 Kawasaki Ninja 250r IL: RUNYON
xbxlive: sirricealot07
ps3: sirricealot7
David Runyon