Find the combination of substrings from a string


import java.util.HashSet;
import java.util.Set;

public class StringCalculator {

static final String WORD = “346789ABCDEFGHJKLMNPQRSTUWXY”;
static final int lengOfSubString = 4;
/**
* @param args
*/
public static void main(String[] args) {

char[] wordArray = WORD.toCharArray();
int lengthOfWord = WORD.length();
System.out.println(“Length of the word : “+lengthOfWord);
String subString = “”;

Set<String> set = new HashSet<String>();
for(int a=0;a<lengthOfWord;a++){
for(int b=0;b<lengthOfWord;b++){
for(int c=0;c<lengthOfWord;c++){
for(int d=0;d<lengthOfWord;d++){
subString = “8”+wordArray[a] + wordArray[b] +wordArray[c]+wordArray[d];
set.add(subString);
}
}
}
}

System.out.println(“Total”+set.size());
}

}

Advertisements

About Praveen Orathel

I am a java web application developer.
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s