Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: password.java

  1. #1
    Junior Member
    Join Date
    Nov 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default password.java

    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!!

  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: password.java

    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

  3. #3
    Junior Member
    Join Date
    Nov 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: password.java

    ok cool...the code is:
    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.
    Last edited by helloworld922; November 11th, 2010 at 03:15 AM.

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: password.java

    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.

  5. #5
    Junior Member
    Join Date
    Nov 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: password.java

    how do i use the code tag...solved the question but now i need it to stop the loop at 3 tries.

  6. #6
    Member Darryl.Burke's Avatar
    Join Date
    Mar 2010
    Location
    Madgaon, Goa, India
    Posts
    494
    Thanks
    8
    Thanked 48 Times in 46 Posts

    Default Re: password.java

    how do i use the code tag
    [code]CODE[/code] will display as
    CODE
    db

Similar Threads

  1. Password Program
    By computercoder in forum What's Wrong With My Code?
    Replies: 10
    Last Post: October 20th, 2010, 07:03 AM
  2. [SOLVED] password denied
    By chronoz13 in forum AWT / Java Swing
    Replies: 3
    Last Post: January 28th, 2010, 09:22 PM
  3. password
    By 5723 in forum Algorithms & Recursion
    Replies: 9
    Last Post: July 9th, 2009, 05:26 AM
  4. [SOLVED] java password
    By pwngrammer in forum File I/O & Other I/O Streams
    Replies: 6
    Last Post: June 15th, 2009, 09:49 AM
  5. Java password generator program to generate 8 random integers
    By Lizard in forum What's Wrong With My Code?
    Replies: 3
    Last Post: May 16th, 2009, 07:49 AM