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.


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

Results 1 to 3 of 3

Thread: Help on a HW assignment if password is valid or invalid?

  1. #1
    Junior Member
    Join Date
    Feb 2011
    Thanked 0 Times in 0 Posts

    Default Help on a HW assignment if password is valid or invalid?

    i don't know why i can't understand how to write some code. maybe it's because it's been a yr since i took my last java class, but i am having trouble in coding this HW.
    this is our given code :
    public class Lab5 {
      public static void main(String[] args) {
        // Prompt the user to enter a password
        java.util.Scanner input = new java.util.Scanner(System.in);
        System.out.print("Enter a string for password: ");
        String s = input.nextLine();
        if (isValidPassword(s)) {
          System.out.println("Valid password");
        else {
          System.out.println("Invalid password");
      /** Check if a string is a valid password */
      public static boolean isValidPassword(String s) {

    we do not have to change anything in the main method, we are suppose to only write code in the isValidPassword method. the requirements are:
    • A password must starts with a letter.
    • A password consists of only letters and digits. - this i think i need a for loop
    • A password must have at least six characters.

    any help is appreciated, thanks

  2. #2
    Join Date
    Feb 2011
    My Mood
    Thanked 16 Times in 15 Posts

    Default Re: Help on a HW assignment if password is valid or invalid?

    This reeks of regular expressions. Please excuse the negative connotation. Just waiting for a guy to swing in from a rope a type in the regex that you need.

    RegEx Resources:
    Cheat Sheet
    Java API regex package
    Regexpal: Realtime Regex tester

    Hope this helps, Good luck
    Last edited by JJeng; March 9th, 2011 at 10:20 PM. Reason: Spelling fail

  3. #3
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    United Kingdom
    My Mood
    Thanked 294 Times in 227 Posts
    Blog Entries

    Default Re: Help on a HW assignment if password is valid or invalid?

    Also see - http://www.javaprogrammingforums.com...explained.html
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

Similar Threads

  1. Identifying invalid calls
    By joshft91 in forum Object Oriented Programming
    Replies: 1
    Last Post: February 26th, 2011, 05:38 PM
  2. Valid toString method?
    By dcshoecousa in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 4th, 2010, 11:55 AM
  3. Replies: 1
    Last Post: February 22nd, 2010, 08:20 AM
  4. Replies: 6
    Last Post: August 30th, 2009, 04:31 AM