Results 1 to 12 of 12
 05292011, 10:24 AM #1Member
 Join Date
 May 2011
 Posts
 18
 Rep Power
 0
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.Last edited by JosAH; 05292011 at 11:02 AM. Reason: removed the big font
 05292011, 10:34 AM #2
 Join Date
 Jan 2011
 Location
 Richmond, Virginia
 Posts
 3,069
 Blog Entries
 3
 Rep Power
 9
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.
 05292011, 10:51 AM #3Member
 Join Date
 May 2011
 Posts
 18
 Rep Power
 0
I have this so far.
Java Code:int z=0; for(y=1;y<10;y++){ for(int x=1;x<=5;x++){ System.out.print("z"); } z++}
it's probably a simple answer but I have not been coding in java for to long.
 05292011, 11:04 AM #4
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 13,931
 Blog Entries
 7
 Rep Power
 22
 05292011, 11:16 AM #5Member
 Join Date
 May 2011
 Posts
 18
 Rep Power
 0
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
 05292011, 11:25 AM #6
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 13,931
 Blog Entries
 7
 Rep Power
 22
cenosillicaphobia: the fear for an empty beer glass
 05292011, 07:22 PM #7Member
 Join Date
 May 2011
 Posts
 18
 Rep Power
 0
Those curly brackets have to match; b.t.w. don't put that curly bracket there; put it on its own line like this:
Java Code:int z=0; for(y=1;y<10;y++){ for(int x=1;x<=5;x++){ System.out.print("z"); } z++; }
Jos
Java 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
 05292011, 07:32 PM #8Member
 Join Date
 May 2011
 Posts
 18
 Rep Power
 0
Ok, so i changed some things around and this is my complete code.
Java 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:
Java 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++){ ^

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.
 05292011, 07:41 PM #10Member
 Join Date
 May 2011
 Posts
 18
 Rep Power
 0
I got a different code from someone else and it works great.
Java Code:int i, j, k, m, n; String d1, d2, d3, d4, d5; String digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; // First print 1digit "numbers" for(i = 0; i < 36; i++){ d1 = digits.substring(i, i+1 ); System.out.println(d1); } System.out.println(); // Next, print 2digit "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 3digit "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 4digit "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 5digit "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); } } } } }

Oh for the love of everything beautiful, at least figure out what you did wrong!
Again, what is the difference between this:
Java Code:for (y=1;y<10;y++){ // causes errors
Java Code:for ([b][color="red"]int[/color][/b] x=1;x<=5;x++){ // no errors
 05292011, 07:47 PM #12Member
 Join Date
 May 2011
 Posts
 18
 Rep Power
 0
Similar Threads

Firt letter with T
By globo in forum New To JavaReplies: 4Last Post: 02252011, 10:04 PM 
OpenFaces 2.0: Open New Possibilities for your Web Applications
By TeamDev in forum Reviews / AdvertisingReplies: 1Last Post: 04012010, 05:09 PM 
How to Determine prime number and making shape using loop?
By cyzash in forum New To JavaReplies: 10Last Post: 02202010, 09:25 PM 
Letter with Letters
By elgatoboricua in forum New To JavaReplies: 7Last Post: 09162008, 02:59 PM 
the number of occurrences of each alphabetical letter in the string.
By masaka in forum New To JavaReplies: 20Last Post: 05142008, 09:42 AM
Bookmarks