I am getting trouble with writing this program. the password:
must have a letter and digit
must be between the range of 6-10
must be in al oop(user cannot move on until it is correct.
plz help!!
Printable View
I am getting trouble with writing this program. the password:
must have a letter and digit
must be between the range of 6-10
must be in al oop(user cannot move on until it is correct.
plz help!!
That's not how this works. This isn't a code service. Ask a specific question and post an SSCCE demonstrating where you're stuck.
How To Ask Questions The Smart Way
ok cool...the code is:
Code Java:import javax.swing.*; public class Password2 { public static void main(String [] args) { int digit=0; int letter=0; String pw1=""; String pw2; int size = pw1.length(); do { pw1=JOptionPane.showInputDialog("enter password: "); size = pw1.length(); { for(int i=0;i<size;i++) { char ch=pw1.charAt(i); if(Character.isDigit(ch)) digit++; if(Character.isLetter(ch)) letter++; } } }while(!(size>=6 && size<=10 && digit>=1 && letter>=1));
everyting works good except i have to:
prompt user to enter password again to confirm it is correct and if the password does not match the first password entered the program suppose to loop.
Then I'd say you should check out your conditional statement. Add some print lines, or use a debugger, to figure out what's going on. What is the value of size, digit, and letter? Is that what you'd expect?
PS- When posting code, make sure you use the CODE tags to preserve formatting.
how do i use the code tag...solved the question but now i need it to stop the loop at 3 tries.
[code]CODE[/code] will display asQuote:
how do i use the code tag
dbCode :CODE