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 9166969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:16:41+00:00 2026-06-17T15:16:41+00:00

I have written a code for random password generation.There are a string from where

  • 0

I have written a code for random password generation.There are a string from where i have to make the password.so i try to categorize the string according to uppercase array , lower case array and digit array. but here comes a problem when..

         for(int k=0;k<Length;k++){
        if(asc[k]>=65 && asc[k]<=90){
            UpperCase[k]=(char)asc[k];
        }
        else if(asc[k]>=48 && asc[k]<=57){
            Digit[k]=(char)asc[k];
        }
        else {
            Mixed[k]=(char)asc[k];
        }
    } 

is executed it counts some space which i don’t want.coding looks like ugly sry for my poor coding.i know there is a lot more way to solve it but i want to go through this.here is my code. here is my code

import java.util.Random;

   public class Randompassgeneration
   {

final int MAX_LENGTH = 20;
final int MIN_LENGTH = 3;

char[] password=new char[25];
int [] asc=new int[18];
char[] UpperCase=new char[25];
char[] Digit=new char[25];
char[] Mixed=new char[25];
public void generate(String allowedCharacters)
{
    int Length=allowedCharacters.length();


    for (int i=0;i<Length;i++)
    {
        asc[i]=(int)allowedCharacters.charAt(i);

    }
    for (int k=0;k<Length;k++)
    {
        if (asc[k]>=65 && asc[k]<=90)
        {
            UpperCase[k]=(char)asc[k];
        }
        else if (asc[k]>=48 && asc[k]<=57)
        {
            Digit[k]=(char)asc[k];
        }
        else
        {
            Mixed[k]=(char)asc[k];
        }
    }

    String rp=null;
    StringBuilder Strbld=new StringBuilder();
    Random rnd=new Random();
    int ranStrLen=rnd.nextInt(MAX_LENGTH - MIN_LENGTH + 1) + MIN_LENGTH;
    Strbld.append(UpperCase[rnd.nextInt(UpperCase.length)]);
    Strbld.append(Digit[rnd.nextInt(Digit.length)]);

    for (int m=0; m<ranStrLen-2; m++)
    {
        Strbld.append(Mixed[rnd.nextInt(Mixed.length)]);

    }

    System.out.print(ranStrLen +"->"+ Strbld.toString());


}

public static void main(String[] args)
{
    String allowedCharacters = "weakPasSWorD1234$*";
    Randompassgeneration t=new Randompassgeneration();
    t.generate(allowedCharacters);
}
}

Any kind of suggestion?

  • 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-06-17T15:16:42+00:00Added an answer on June 17, 2026 at 3:16 pm

    “is executed it counts some space which i don’t want”

    The white space is beacuse of your For loop

    You were using the variable k for all the arrays,which resulted into the incremented value of k each time.So,this was making “gaps” between your arrays.

    Change it to:

    int point1=0,point2=0,point3=0;
    for (int k=0;k<Length;k++)
    {
        if (asc[k]>=65 && asc[k]<=90)
        {
            UpperCase[point1]=(char)asc[k];point1++;
            continue;
        }
        else if (asc[k]>=48 && asc[k]<=57)
        {
            Digit[point2]=(char)asc[k];point2++;
            continue;
        }
        else
        {
            Mixed[point3]=(char)asc[k];point3++;
        }
    
    }
    System.out.println(UpperCase);
    System.out.println(Digit);
    System.out.println(Mixed);
    

    OutPut:

    PSWD
    1234
    weakasor$*
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written the program, which chooses a random element from the array. Once
I have written this code inside a servlet to delete certain records from three
I have written a code for taking JSON data from a PHP and putting
I've written a very simple python numpy code. It have a strange behavior... from
I have written the following code to generate random numbers in C. int main
I have written a code in MATLAB that allows me to generate a random
Here is the code I have written: function p_deal(id) { var card1_val = Math.floor(Math.random()
I have never written a single line of Haskell code (except for random stuff
I have written a source code to print random numbers within a specified limit.But
I have written a javascript code to show users a random quote every 10

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.