Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 699827
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T03:25:46+00:00 2026-05-14T03:25:46+00:00

I am trying to make a program in Java that checks for three specific

  • 0

I am trying to make a program in Java that checks for three specific inputs. It has to have pass these tests:

  1. At least 7 characters.
  2. Contain both upper and lower case alphabetic characters.
  3. Contain at least 1 digit.

So far I have been able to make it check if there is 7 characters, but I am having trouble with the last two. What should I put in my loop as an if statement to check for digits and make it upper and lower case. Any help would be greatly appreciated.
Here is what I have so far.

import java.awt.*;
import java.io.*;
import java.util.StringTokenizer;

public class passCheck
{


    private static String getStrSys ()
    {
        String myInput = null;          //Store the String that is read in from the command line

        BufferedReader mySystem;        //Buffer to store the input

        mySystem = new BufferedReader (new InputStreamReader (System.in)); //creates a connection to system input
        try
        {
            myInput = mySystem.readLine (); //reads in data from the console
            myInput = myInput.trim ();
        }
        catch (IOException e)  //check
        {
            System.out.println ("IOException: " + e);
            return "";
        }
        return myInput; //return the integer to the main program
    }


    //****************************************
    //main instructions go here
    //****************************************

    static public void main (String[] args)
    {

        String pass;         //the words the user inputs
        String temp = "";            //holds temp info

        int stringLength;          //length of string
        boolean goodPass = false;


        System.out.print ("Please enter a password: ");  //ask for words

        pass = getStrSys ();                              //get words from system
        temp = pass.toLowerCase ();
        stringLength = pass.length ();             //find length of eveyrthing



        while (goodPass == false)

            {
                if (stringLength < 7)
                {
                    System.out.println ("Your password must consist of at least 7 characters");
                    System.out.print ("Please enter a password: ");  //ask for words
                    pass = getStrSys ();
                    stringLength = pass.length ();
                    goodPass = false;
                }
                else if (/* something to check for digits */)
                {

                }

            }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T03:25:46+00:00Added an answer on May 14, 2026 at 3:25 am

    Sure you can come up with a convoluted—almost unreadable—regex for doing this but I wouldn’t suggest it. Apart from the readability aspect, if the password fails it doesn’t tell you why. This solves both of these problems:

    while (true) {
      pass = getStrSys();
      if (pass.length() < 7) {
        System.out.println("must be at least 7 characters long");
      } else {
        boolean upper = false;
        boolean lower = false;
        boolean number = false;
        for (char c : pass.toCharArray()) {
          if (Character.isUpperCase(c)) {
            upper = true;
          } else if (Character.isLowerCase(c)) {
            lower = true;
          } else if (Character.isDigit(c)) {
            number = true;
          }
        }
        if (!upper) {
          System.out.println("must contain at least one uppercase character");
        } else if (!lower) {
          System.out.println("must contain at least one lowercase character");
        } else if (!number) {
          System.out.println("must contain at least one number");
        } else {
          break;
        }
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 440k
  • Answers 440k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer There isn't enough information in the question, as it stands,… May 15, 2026 at 5:16 pm
  • Editorial Team
    Editorial Team added an answer Is there a reason you need this as a collection… May 15, 2026 at 5:16 pm
  • Editorial Team
    Editorial Team added an answer You first need to add it in the Server explorer… May 15, 2026 at 5:16 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.