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.

Loop to note position of lowest number

Hi guys,

I have a password key which is "password12Qcb6z:!sh:&BYztwYTPM" which i have repeating a number of times in a 1d array.

What i am trying to create an array where numbers are assigned starting with 1, and they are assigned first by alphabetical order, and second, where the same letter appears twice, by position in the word.

for example:

C O N V E N I E N C E
1 10 7 11 3 8 6 4 9 2 5

my key is alot longer than "CONVENIENCE" its roughly 328 characters long ("password12Qcb6z:!sh:&BYztwYTPM" repeated ). so i have a 1d int array array which i want to map out 1-328 following the rule above starting wit the lowest character in its ascii values 32 = SPACE to ~ = 127. so i then have a array mapping out 1-328 ...

I have this code so far

int v=0, count=0, r=32; // 33 is the first usable ascii character in test file
int[] colprintorder = new int[numberofcols];
while(r<=127) // loop unit last usable ascii char
{
for(int i=0;i<passwordinbyte.length;i++) // go through each cell of the array
{
if (r == passwordinbyte[i]) // if the value of r is the same as what is in passwordinbyte map its position storing in colprintorder
{
colprintorder[count] = i ;
count++; // next cell in the array
}
}
r++; // look for the next characters ascii value 32-127
}
for(int a=0; a<colprintorder.length; a++) // print out colprint order
{
System.out.println( colprintorder[a] + " " );
}
System.out.println("lengthhrr" +passwordinbyte.length);

Re: Loop to note position of lowest number

So, you are wanting to get the ASCII values of all of the characters, then determine, based on their ASCII values, which come first, second, third, ect.

If so, I am unsure why you have all that code. You can convert a String to a char[] using the String.toCharArray() method, then sort the char[] with the Arrays.sort(char[]) method, then do whatever with the sorted array.

which is the word sorted based on each character's ASCII value.
Similarly, if I input password12Qcb6z:!sh:&BYztwYTPM it outputs:

!&126::BMPQTYYabcdhoprssstwwzz

Am I totally off?

NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

When asking for help, please follow these guidelines to receive better and more prompt help:
1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
2. Give full details of errors and provide us with as much information about the situation as possible.
3. Give us an example of what the output should look like when done correctly.

Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/