Page 2 of 2 FirstFirst 12
Results 21 to 28 of 28
  1. #21
    DarkAlex is offline Member
    Join Date
    Mar 2011
    Posts
    10
    Rep Power
    0

    Default

    Quote Originally Posted by Junky View Post
    No.

    The indexOf method returns the position in the String where the target char is located or -1 if it is not found. EG in the String "hello world" the indexOf('w') call would return 6, the indexOf('h') call would return 0 and the indexOf('z') call would return -1.
    So then how does this become boolean, exactly? That's my main problem I'm having.
    It's returning an int if it's returning 6...

  2. #22
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,789
    Rep Power
    7

    Default

    I just posted some pseudocode if you missed it.

  3. #23
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,789
    Rep Power
    7

    Default

    Ahh carp I just realised the pseudo code still wont work. You will have to check for all three chars in one if statement.

  4. #24
    DarkAlex is offline Member
    Join Date
    Mar 2011
    Posts
    10
    Rep Power
    0

    Default

    import java.util.Scanner;

    public class CS1_Frazer_X7_2
    {
    public static void main(String[] args)
    {
    String input;

    System.out.println("Please enter new password");

    Scanner k = new Scanner(System.in);
    input = k.nextLine();

    if(input.length()>=8){
    System.out.println("Password Approved");
    }else{
    System.out.println("Password Denied");
    if(input.indexOf('#')==-1)

    }
    }
    }
    }
    }
    }


    -------
    Slightly improved, however, it still faces some problems... mostly that pesky thing where it needs to one or more of the three symbols.

  5. #25
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    Say you wanted to test if a number was either 0 or anywhere up to infinity, how would you do that?

  6. #26
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,789
    Rep Power
    7

    Default

    Java Code:
    if(input.length()>=8){
        System.out.println("Password Approved");
    }else{
        System.out.println("Password Denied");
    }
    You cannot do this. You must perform ALL tests before you can determine if the password is valid or not. This is why I keep suggesting to use a boolean. If you are not going to follow the advice given then I do not see any point in trying to help.

  7. #27
    DarkAlex is offline Member
    Join Date
    Mar 2011
    Posts
    10
    Rep Power
    0

    Default

    Quote Originally Posted by Junky View Post
    Java Code:
    if(input.length()>=8){
        System.out.println("Password Approved");
    }else{
        System.out.println("Password Denied");
    }
    You cannot do this. You must perform ALL tests before you can determine if the password is valid or not. This is why I keep suggesting to use a boolean. If you are not going to follow the advice given then I do not see any point in trying to help.
    The reason I haven't used a boolean...
    Is because I don't know how.
    Can you explain?

  8. #28
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,789
    Rep Power
    7

    Default

    Java Code:
    boolean positive = true;
    int number = -5;
    if(number < 0) {
        positive = false;
    }
    if(positive) {
        System.out.println("A positive number");
    } else {
        System.out.println("A negative number");
    }

Page 2 of 2 FirstFirst 12

Similar Threads

  1. user name and password validation
    By exose in forum New To Java
    Replies: 6
    Last Post: 01-20-2011, 02:59 PM
  2. Password
    By Adomini in forum New To Java
    Replies: 3
    Last Post: 09-20-2010, 10:43 AM
  3. how to check password for 3 times enterd wrong password
    By sk.mahaboobbhasha@gmail.c in forum New To Java
    Replies: 2
    Last Post: 11-14-2008, 07:53 PM
  4. how to check password for 3 times enterd wrong password
    By sk.mahaboobbhasha@gmail.c in forum Java Servlet
    Replies: 0
    Last Post: 11-14-2008, 01:22 PM
  5. How to check password of a jsp/html with the password of Database(mysql) #1
    By sk.mahaboobbhasha@gmail.c in forum Java Servlet
    Replies: 2
    Last Post: 11-14-2008, 01:11 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •