Results 1 to 8 of 8
- 11-22-2010, 12:42 PM #1
Member
- Join Date
- Nov 2010
- Location
- Beirut, Lebanon
- Posts
- 36
- Rep Power
- 0
code wont enter into loop. thanks in advance for your help
im writing a password check program.
i want it to give "a valid password" if the rules are satisfied and "not a valid password" if they are not, along with the violated rules. but it wont enter into the first loop if i put for example "cmps200" which is a correct password it would type "not a valid password" any suggestions(if it helps the rules are length>6 and <15, at least a digit and at least a number and doesnt end with 99 after a sequence of alphabetical letters)
if(((len > 6) && (len < 15)) && ((charCount > 0)&& (intCount> 0)) && ((charCount > 0) &&((S.charAt(len-1)) != '9' && (S.charAt(len-2) != '9')))) //all rules satisfied
{
if ((charCount > 0) && (intCount> 0))
{
if ((charCount > 0) && ((S.charAt(len-1) != '9') && (S.charAt(len-2) != '9')))
{
System.out.println("a valid password");
}
}
}
else
{
System.out.println("not a valid password");
if ((len < 6) || (len > 15))
{
System.out.println("rule 1 violated");
}
i posted up to rule one.
- 11-22-2010, 12:55 PM #2
your if part is confusing ..
You post a code .Then only we can understand what charCount,intCount and how you are manipulating to come to this if etc we will know.
It's highly impossible to give solution without knowing head and foot.Last edited by RamyaSivakanth; 11-22-2010 at 01:17 PM.
Ramya:cool:
- 11-22-2010, 01:14 PM #3
Member
- Join Date
- Nov 2010
- Location
- Beirut, Lebanon
- Posts
- 36
- Rep Power
- 0
charCount is used to count if there are any characters and intCount to count if there are any integers
(used to check that at least there is 1 integer and character) and !9 since i dnt want the last two digits to be nine if it is proceeded by an alphabetical sequence.
thanks
- 11-22-2010, 01:22 PM #4
You are not getting what Iam saying...Iam able to get your requirement.
But,my question is you just post your code for getting charCount and intCount.I want to see to correct you.Ramya:cool:
- 11-22-2010, 01:28 PM #5
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Also use code tags.
The lack of formatting in that code makes it hard to see the flow.
- 11-22-2010, 01:30 PM #6
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,427
- Blog Entries
- 7
- Rep Power
- 17
[QUOTE=farahm;158354]
You're overcomplicating matters (you have included too many redundant tests and too many parentheses). This should do it:
kind regards,Java Code:if (len > 6 && len < 15 && charCount > 0 && intCount > 0 && (S.charAt(len-1) != '9' || S.charAt(len-2) != '9')) //all rules satisfied System.out.println("a valid password"); else System.out.println("not a valid password");
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 11-22-2010, 02:06 PM #7
Member
- Join Date
- Nov 2010
- Location
- Beirut, Lebanon
- Posts
- 36
- Rep Power
- 0
i figured it out
what was wrong with the code is that between each condition/rule i should have put || not &&(or not and).
- 11-22-2010, 02:38 PM #8
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,427
- Blog Entries
- 7
- Rep Power
- 17
It's just boolean logic: let E be the condition that the last character is a '9', let F be the condition that the second to last character is a '9'. So:
You don't want both of them to be true (then the String S ends with 99), in other words: !(E&&F) == !E || !F; this translates to Java as:Java Code:E: S.charAt(len-1) == '9' F: S.charAt(len-2) == '9'
kind regards,Java Code:S.charAt(len-1) != '9' || S.charAt(len-2) != '9'
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
Similar Threads
-
How enter this mode-gui/design-view/code-view
By lse123 in forum NetBeansReplies: 0Last Post: 02-28-2010, 09:09 PM -
Finding Most Effecient Distribution of Change -- Won't Enter Loop
By Cod in forum New To JavaReplies: 18Last Post: 11-29-2009, 11:58 PM -
[SOLVED] how to run loop unless and until user enter correct value
By mfaizan24 in forum New To JavaReplies: 21Last Post: 06-11-2009, 02:18 AM -
what code for not hitting enter?
By tornbacchus in forum New To JavaReplies: 4Last Post: 04-11-2009, 04:59 AM -
simple problem - code wont compile
By dirtycash in forum New To JavaReplies: 1Last Post: 11-20-2007, 05:49 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks