# Loop through all letter and number possibilities?

• 05-29-2011, 10:24 AM
Mr.abe90
Loop through all letter and number possibilities?
What I mean is how do i make a loop in java that cycles through all possible combinations of letters and numbers (with a limit of course). Like have it start with 0 and next have it be 00, 000, 0000... And then after like 5 digits of zeros have a 1 added (00001) And continue on adding letters.

I realize it would take a very long time to list them all but i still want to know what the code would be like.
• 05-29-2011, 10:34 AM
sunde887
We don't really write code for people, instead we help people out. Have you tried this yet? If so, why not post your code(with [code] tags [/code]) and any problems you are having.
• 05-29-2011, 10:51 AM
Mr.abe90
I have this so far.
Code:

```int z=0; for(y=1;y<10;y++){ for(int x=1;x<=5;x++){ System.out.print("z"); } z++}```
Te error is ';' expected in "z++}"
it's probably a simple answer but I have not been coding in java for to long.
• 05-29-2011, 11:04 AM
JosAH
Quote:

Originally Posted by Mr.abe90
I have this so far.
Code:

```int z=0; for(y=1;y<10;y++){ for(int x=1;x<=5;x++){ System.out.print("z"); } z++}```
Te error is ';' expected in "z++}"
it's probably a simple answer but I have not been coding in java for to long.

Not long enough: in Java statements are terminated by a semi colon; you forgot one and the compiler started to whine about it.

kind regards,

Jos
• 05-29-2011, 11:16 AM
Mr.abe90
Quote:

Not long enough: in Java statements are terminated by a semi colon; you forgot one and the compiler started to whine about it.

kind regards,

Jos
Well am I suppost to put the semi colon before the "}", after z++} or get rid of the "}"?
• 05-29-2011, 11:25 AM
JosAH
Quote:

Originally Posted by Mr.abe90
Well am I suppost to put the semi colon before the "}", after z++} or get rid of the "}"?

Those curly brackets have to match; b.t.w. don't put that curly bracket there; put it on its own line like this:

Code:

```int z=0; for(y=1;y<10;y++){   for(int x=1;x<=5;x++){       System.out.print("z");   }   z++; }```
kind regards,

Jos
• 05-29-2011, 07:22 PM
Mr.abe90
Quote:

Those curly brackets have to match; b.t.w. don't put that curly bracket there; put it on its own line like this:

Code:

```int z=0;     for(y=1;y<10;y++){       for(int x=1;x<=5;x++){           System.out.print("z");       }       z++;     }```
kind regards,

Jos

These are the errors I get when i type that exact code.
Code:

```Password.java:3: illegal start of type for(y=1;y<10;y++){ ^ Password.java:3: <identifier> expected for(y=1;y<10;y++){     ^ Password.java:3: ';' expected for(y=1;y<10;y++){       ^ Password.java:3: illegal start of type for(y=1;y<10;y++){           ^ Password.java:3: <identifier> expected for(y=1;y<10;y++){             ^ Password.java:3: ';' expected for(y=1;y<10;y++){             ^ Password.java:3: illegal start of type for(y=1;y<10;y++){               ^ Password.java:3: <identifier> expected for(y=1;y<10;y++){                 ^ Password.java:3: ';' expected for(y=1;y<10;y++){                 ^ Password.java:4: illegal start of type   for(int x=1;x<=5;x++){   ^ Password.java:4: <identifier> expected   for(int x=1;x<=5;x++){       ^ Password.java:4: ';' expected   for(int x=1;x<=5;x++){       ^ Password.java:4: <identifier> expected   for(int x=1;x<=5;x++){             ^ Password.java:4: <identifier> expected   for(int x=1;x<=5;x++){                 ^ Password.java:4: illegal start of type   for(int x=1;x<=5;x++){                   ^ Password.java:4: <identifier> expected   for(int x=1;x<=5;x++){                   ^ Password.java:4: ';' expected   for(int x=1;x<=5;x++){                     ^ Password.java:4: illegal start of type   for(int x=1;x<=5;x++){                     ^ Password.java:4: <identifier> expected   for(int x=1;x<=5;x++){                       ^ Password.java:4: ';' expected   for(int x=1;x<=5;x++){                         ^ Password.java:5: <identifier> expected       System.out.print("z");                       ^ Password.java:5: illegal start of type       System.out.print("z");                       ^ Password.java:7: class, interface, or enum expected   z++;   ^ Password.java:8: class, interface, or enum expected } ^ 24 errors```
I have no idea what to do.
:frusty:
• 05-29-2011, 07:32 PM
Mr.abe90
Ok, so i changed some things around and this is my complete code.
Code:

```public class Project1 {         public static void main(String[] args) {                 int z=0;                 for(y=1;y<10;y++){                         for(int x=1;x<=5;x++){                                 System.out.print("z");                         }                         z++;                 }         } }```

The errors are:
Code:

```cannot find symbol symbol  : variable y                 for(y=1;y<10;y++){                     ^                 for(y=1;y<10;y++){                         ^                 for(y=1;y<10;y++){                             ^```
• 05-29-2011, 07:37 PM
Fubarable
The solution is already in your code: Look at the difference between the the x for loop that has no errors and the y for loop that has the errors.
• 05-29-2011, 07:41 PM
Mr.abe90
I got a different code from someone else and it works great.
Code:

```int i, j, k, m, n;         String d1, d2, d3, d4, d5;         String digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";                 // First print 1-digit "numbers"         for(i = 0; i < 36; i++){             d1 = digits.substring(i, i+1 );             System.out.println(d1);         }                         System.out.println();                                     // Next, print 2-digit "numbers"         for(i = 0; i < 36; i++){             d1 = digits.substring(i, i+1 );             for( j = 0; j < 36; j++ ) {                 d2 = d1 + digits.substring(j, j+1 );                 System.out.println(d2);             }         }                         System.out.println();                         // Now print 3-digit "numbers"         for(i = 0; i < 36; i++){             d1 = digits.substring(i, i+1 );             for( j = 0; j < 36; j++ ) {                 d2 = d1 + digits.substring(j, j+1 );                 for( k = 0; k < 36; k++ ) {                     d3 = d2 + digits.substring(k, k+1 );                     System.out.println(d3);                 }             }         }                             System.out.println();                         // Now print 4-digit "numbers"         for(i = 0; i < 36; i++){             d1 = digits.substring(i, i+1 );             for( j = 0; j < 36; j++ ) {                 d2 = d1 + digits.substring(j, j+1 );                 for( k = 0; k < 36; k++ ) {                     d3 = d2 + digits.substring(k, k+1 );                     for( m = 0; m < 36; m++) {                         d4 = d3 + digits.substring( m, m+1 );                         System.out.println(d4);                     }                 }             }         }                             System.out.println();                         // Finally, print 5-digit "numbers"         for(i = 0; i < 36; i++){             d1 = digits.substring(i, i+1 );             for( j = 0; j < 36; j++ ) {                 d2 = d1 + digits.substring(j, j+1 );                 for( k = 0; k < 36; k++ ) {                     d3 = d2 + digits.substring(k, k+1 );                     for( m = 0; m < 36; m++) {                         d4 = d3 + digits.substring( m, m+1 );                         for( n = 0; n < 36; n++) {                             d5 = d4 + digits.substring( n, n+1 );                             System.out.println(d5);                         }                     }                 }             }         }```
But Thanks For All Your Help!
• 05-29-2011, 07:44 PM
Fubarable
Oh for the love of everything beautiful, at least figure out what you did wrong!

Again, what is the difference between this:
Code:

`for (y=1;y<10;y++){ // causes errors`
and this:
Code:

`for ([b][color="red"]int[/color][/b] x=1;x<=5;x++){  // no errors`
• 05-29-2011, 07:47 PM
Mr.abe90
Quote:

Oh for the love of everything beautiful, at least figure out what you did wrong!

Again, what is the difference between this:
Code:

`for (y=1;y<10;y++){ // causes errors`
and this:
Code:

`for (int x=1;x<=5;x++){  // no errors`

I know I did eventually figure to do just that.
Works fine now.