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 5 of 5

Thread: Whats wrong with my code?

  1. #1
    Junior Member
    Join Date
    Jun 2021
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile Whats wrong with my code?

    This code is supposed to be a password checker that adds the password to an array once it fits into the requirements which checking to see if its been added previously. If it has been added before, it tells you and doesn't add it. BUT it only does this for the first password that has been inputted. I'm pretty new to coding, so any help is greatly appreciated.

    import java.util.Scanner;
     
     
    class Main {
      public static void main(String[] args) {
     
     
     System.out.print("\033[H\033[2J");
     String password; 
     String[]Rpassword = {null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null};
     int yo = 0, count; 
     
     while(yo <= 20){{
     
             int sum = 0;
             int min = 7;
             int digit = 0;
             int Upper = 0;
             int Lower = 0;
     
        System.out.println();
        Scanner scan = new Scanner(System.in);
        System.out.println("Enter Your Password: ");
            password = scan.nextLine();
     
     
           if (password.length() < min) {
             System.out.println("Your password is under 7 charcters");
            }else{
     
     
     
     
     
     
             char c;
     
             for (int i = 0; i < password.length(); i++) {
     
              c = password.charAt(i); 
     
              if(Character.isUpperCase(c)){
              Upper++;}
     
              if(Character.isLowerCase(c)){
              Lower++;}
     
              if(Character.isDigit(c)){
              digit++;}
     
             }
     
              sum = Upper + Lower + digit;
     
              if (password.length() != sum){
     
               System.out.println("Please remove a special character from your password and try again");
              }else if (!(Upper >= 1 )){
     
               System.out.println("Please add at least one uppercase letter to your password and try again");
              }else if (!(Lower >= 1 )){
     
               System.out.println("Please add at least one lowercase letter to your password and try again");
                }else if (!(digit >= 1 )){
     
               System.out.println("Please add at least one number to your password and try again");
     
               }else{ System.out.println("Your password fits all categories! ");
     
               for (int d = 0; d < Rpassword.length; d++) {
                if (password.equals(Rpassword[d])){
                //if (Rpassword[d].equals(password)){
                System.out.println("This password was already said, input another one");
                break;
                }else{
     
                Rpassword[yo] = password;
                System.out.println("Your password is stored in the " + yo + " space");
                yo = yo + 1;
     
               break;}}
     
     
     
               }
     
     
     
            }
     
        }
      }
     }}
    This code is supposed to be a password checker that adds the password to an array once it fits into the requirements which checking to see if its been added previously. If it has been added before, it tells you and doesn't add it. BUT it only does this for the first password that has been inputted. I'm pretty new to coding, so any help is greatly appreciated.

    import java.util.Scanner;
     
     
    class Main {
    public static void main(String[] args) {
     
     
    System.out.print("\033[H\033[2J");
    String password;
    String[]Rpassword = {null,null,null,null,null,null,null,null,null,null ,null,null,null,null,null,null,null,null,null,null ,null};
    int yo = 0, count;
     
    while(yo <= 20){{
     
    int sum = 0;
    int min = 7;
    int digit = 0;
    int Upper = 0;
    int Lower = 0;
     
    System.out.println();
    Scanner scan = new Scanner(System.in);
    System.out.println("Enter Your Password: ");
    password = scan.nextLine();
     
     
    if (password.length() < min) {
    System.out.println("Your password is under 7 charcters");
    }else{
     
     
     
     
     
     
    char c;
     
    for (int i = 0; i < password.length(); i++) {
     
    c = password.charAt(i);
     
    if(Character.isUpperCase(c)){
    Upper++;}
     
    if(Character.isLowerCase(c)){
    Lower++;}
     
    if(Character.isDigit(c)){
    digit++;}
     
    }
     
    sum = Upper + Lower + digit;
     
    if (password.length() != sum){
     
    System.out.println("Please remove a special character from your password and try again");
    }else if (!(Upper >= 1 )){
     
    System.out.println("Please add at least one uppercase letter to your password and try again");
    }else if (!(Lower >= 1 )){
     
    System.out.println("Please add at least one lowercase letter to your password and try again");
    }else if (!(digit >= 1 )){
     
    System.out.println("Please add at least one number to your password and try again");
     
    }else{ System.out.println("Your password fits all categories! ");
     
    for (int d = 0; d < Rpassword.length; d++) {
    if (password.equals(Rpassword[d])){
    //if (Rpassword[d].equals(password)){
    System.out.println("This password was already said, input another one");
    break;
    }else{
     
    Rpassword[yo] = password;
    System.out.println("Your password is stored in the " + yo + " space");
    yo = yo + 1;
     
    break;}}
     
     
     
    }
     
     
     
    }
     
    }
    }
    }}
    Last edited by Norm; June 14th, 2021 at 12:46 PM. Reason: merged duplicates / fixed code tags

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Whats wrong with my code?

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.

    Unformatted code is hard to read and understand.

    Please copy the contents of the console from when you execute the code that shows what you are asking about.
    Add some comments to the output where the output is not what is desired.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Whats wrong with my code?

    The posted code has lost all its formatting. The correctly formatted code needs to have the code tags added to it.
    I don't know how all the formatting was lots when the code tags were added. Please try again to have properly formatted code.
    I have fixed it for you.

    Please copy the contents of the console from when you execute the code that shows what you are asking about.
    Add some comments to the output where the output is not what is desired.
    If you don't understand my answer, don't ignore it, ask a question.

  4. #4
    Junior Member
    Join Date
    Jun 2021
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Whats wrong with my code?

    Hey norm,

    I dont know how :/
    I appreciate your help but I think I give up

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Whats wrong with my code?

    How are you executing the program? What console is the output shown on? There must be a way to copy the contents of that console into the clipboard so that it can be pasted here in your post.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Help! Whats wrong with my code?
    By Carolineawood in forum What's Wrong With My Code?
    Replies: 9
    Last Post: October 5th, 2014, 06:56 PM
  2. Whats wrong with my code
    By ansiaries in forum What's Wrong With My Code?
    Replies: 5
    Last Post: April 25th, 2014, 06:41 PM
  3. Whats wrong with my code?
    By green001 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: January 10th, 2014, 06:02 PM
  4. Can someone see whats wrong with my code, please?
    By DJBENZ10 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: July 11th, 2012, 08:54 PM
  5. Whats wrong with my code?
    By mlan in forum What's Wrong With My Code?
    Replies: 3
    Last Post: November 27th, 2010, 01:42 PM

Tags for this Thread