Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-30-2007, 06:04 AM
Member
 
Join Date: Nov 2007
Posts: 2
codingisfun22 is on a distinguished road
String generation
Hi,

I need to create strings based upon the following input data:

S1 = {a,b}
S2 = {1,2,3}

Where you take one element from S1 and combine it with S2. In this example, you would get these strings:

a1,a2,a3,b1,b2,b3

The number of input sets is not necessarily known, and the number of elements in each set is known before the program runs.

Does anyone have any ideas?

Thanks
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 11-30-2007, 07:29 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 2,338
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
I'll give a simple code here. Here the output developed by using characters. So have to think about a way to concatenate those characters and make as strings.

Code:
public class StringTest { public static void main(String[] arguments) { String s1 = "abc"; String s2 = "123"; int s1Len = s1.length(); int s2Len = s2.length(); for(int temp1 =0;temp1 < s1Len;temp1++) { for(int temp2 = 0;temp2 < s2Len;temp2++) { char ch1=s1.charAt(temp1); System.out.print(ch1); char ch2=s2.charAt(temp2); System.out.println(ch2); } } } }
Check there how final strings are obtained using print() and println()
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 11-30-2007, 02:25 PM
Member
 
Join Date: Nov 2007
Posts: 2
codingisfun22 is on a distinguished road
Hi Eranga,

Thank you for the response. I am trying to avoid using a for loop for each set, because I may end up with 36+ sets of characters that I may need to combine together.

I am looking for a solution that will allow this flexibility without using multiple for loops.



Quote:
Originally Posted by Eranga View Post
I'll give a simple code here. Here the output developed by using characters. So have to think about a way to concatenate those characters and make as strings.

Code:
public class StringTest { public static void main(String[] arguments) { String s1 = "abc"; String s2 = "123"; int s1Len = s1.length(); int s2Len = s2.length(); for(int temp1 =0;temp1 < s1Len;temp1++) { for(int temp2 = 0;temp2 < s2Len;temp2++) { char ch1=s1.charAt(temp1); System.out.print(ch1); char ch2=s2.charAt(temp2); System.out.println(ch2); } } } }
Check there how final strings are obtained using print() and println()
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 12-03-2007, 06:43 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 2,338
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
How about arrays.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
EJB generation with xdoclet tags gugas Enterprise JavaBeans 0 02-18-2008 02:07 PM
random generation carlos123 New To Java 10 01-09-2008 04:43 AM
Using java.util.Scanner to search for a String in a String Java Tip Java Tips 0 11-20-2007 05:59 PM
Help with insertName(String name) and deleteName(String name) trill New To Java 1 08-07-2007 08:29 AM
I can't seem to pass the value of a string variable into a string array mathias Java Applets 1 08-03-2007 11:52 AM


All times are GMT +3. The time now is 02:56 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org