Start learning free

LESSON 164 OF 410 · PROJECTS: EVERYDAY PROGRAMS

Password Strength V1 - Length Check in Java

Practice

A tiny password strength checker that looks only at the length of the password.

You start with:

String password = "Secret99";

Build:

Password length: 8
OK

Rules:

  • Print "Password length: " followed by the number of characters.
  • If the length is at least 8, print OK; otherwise print Too short.

Try other passwords: with abc the output is

Password length: 3
Too short

Java's String.length() is a method (with parentheses).

String password = "Secret99";

int length = password.length();
System.out.println("Password length: " + length);
if (length >= 8) {
    System.out.println("OK");
} else {
    System.out.println("Too short");
}

STEP 1 OF 4
    Ctrl + Enter to check

    Password Strength V1 in Java

    Keep going with JavaAbout 340 step-by-step lessons, from your first line of code to coding interviews. Free to start.
    Start learning free