Results 1 to 12 of 12
- 05-29-2011, 10:24 AM #1
Member
- 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; 05-29-2011 at 11:02 AM. Reason: removed the big font
- 05-29-2011, 10:34 AM #2
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
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 #3
Member
- Join Date
- May 2011
- Posts
- 18
- Rep Power
- 0
I have this so far.
Te error is ';' expected in "z++}"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.
- 05-29-2011, 11:04 AM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,392
- Blog Entries
- 7
- Rep Power
- 17
- 05-29-2011, 11:16 AM #5
Member
- Join Date
- May 2011
- Posts
- 18
- Rep Power
- 0
Well am I suppost to put the semi colon before the "}", after z++} or get rid of the "}"?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:25 AM #6
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,392
- Blog Entries
- 7
- Rep Power
- 17
When people rob a bank they get a penalty; when banks rob people they get a bonus.
- 05-29-2011, 07:22 PM #7
Member
- Join Date
- May 2011
- Posts
- 18
- Rep Power
- 0
These are the errors I get when i type that exact code.Those curly brackets have to match; b.t.w. don't put that curly bracket there; put it on its own line like this:
kind regards,Java Code:int z=0; for(y=1;y<10;y++){ for(int x=1;x<=5;x++){ System.out.print("z"); } z++; }
Jos
I have no idea what to do.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
- 05-29-2011, 07:32 PM #8
Member
- 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.
- 05-29-2011, 07:41 PM #10
Member
- Join Date
- May 2011
- Posts
- 18
- Rep Power
- 0
I got a different code from someone else and it works great.
But Thanks For All Your Help!Java 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); } } } } }
-
Oh for the love of everything beautiful, at least figure out what you did wrong!
Again, what is the difference between this:
and 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
- 05-29-2011, 07:47 PM #12
Member
- Join Date
- May 2011
- Posts
- 18
- Rep Power
- 0
Similar Threads
-
Firt letter with T
By globo in forum New To JavaReplies: 4Last Post: 02-25-2011, 09:04 PM -
OpenFaces 2.0: Open New Possibilities for your Web Applications
By TeamDev in forum Reviews / AdvertisingReplies: 1Last Post: 04-01-2010, 05:09 PM -
How to Determine prime number and making shape using loop?
By cyzash in forum New To JavaReplies: 10Last Post: 02-20-2010, 08:25 PM -
Letter with Letters
By elgatoboricua in forum New To JavaReplies: 7Last Post: 09-16-2008, 02:59 PM -
the number of occurrences of each alphabetical letter in the string.
By masaka in forum New To JavaReplies: 20Last Post: 05-14-2008, 09:42 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks