Peer-reviewed code snippets that anyone can edit
follow refactory on twitter
blog
feedback
A wiki for useful code snippets
Bugs? Suggestions?
38-107-191-111
create/login
options
RECENT
STUBS/REQUESTS
STARRED
ACTIVITY
ADD
Add a snippet
Your work won't be attributed to you
because you aren't logged in.
Login using OpenID or an existing username, or create a username
(no email required) before posting.
Snippet title
short summary
Was this snippet already added?
Languages
Comma separated. Like
ruby, rails
or
java, swing
Keywords
Comma separated. Like
file, network
Mark as stub
Snippet
Wrap code in
[code=
language
][/code]
- Use
WikiText markup
outside of [code] tags
[code=java] public class SeqGen { public static void main(String[] args) { // This is the configurable param int seqWidth = 3; int charSetSize = 26; // The size of the array will be 26 ^ seqWidth. ie: if 2 chars wide, 26 // * 26. 3 chars, 26 * 26 * 26 int total = (int)Math.pow(charSetSize, seqWidth); StringBuilder[] sbArr = new StringBuilder[total]; // Initializing the Array for (int j = 0; j <total; j++) { sbArr[j] = new StringBuilder(); } char ch = 'A'; // Iterating over the entire length for the 'char width' number of times. // TODO: Can these iterations be reduced? for (int k = seqWidth; k > 0; k--) { // Iterating and adding each char to the entire array. for (int l = 0; l < total; l++) { sbArr[l].append(ch); if (l % Math.pow(charSetSize, k-1) == 0) { ch++; if (ch > 'Z') { ch = 'A'; } } } } // Use the stringbuilder array. for (StringBuilder builder : sbArr) { System.out.println(builder.toString()); } } } [/code]
Log message
Human?
public snippets
This is a community-maintained collection of reusable code snippets.
Contribute something
without logging in, or improve existing contributions. All code is dedicated to the public domain unless otherwise specified.
stats
/
top contributers