Closed Thread
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-21-2009, 12:34 PM
Member
 
Join Date: Oct 2009
Posts: 24
Rep Power: 0
nmvictor is on a distinguished road
Question How do I list values of an arrays in a comma seperted list
HI everyone, I am working on an application to help students in our university register units(well don't mind units, something like subjects to be undertaken in a particular semester) on-line.Now I have everything working up to the point of registration so definitely it would be a good idea to tell the student of not only the successful unit registration but also list the successfully registered units.During the registration, the students input is a line containing the following information
Code:
 CAMPUSNAME REG-NUMBER UNIT1-UNIT2-UNIT3-...-UNIT8.
I split the above with the code below
Code:
System.out.println("Enter CAMPUSNAME REG-NUMBER UNIT1-UNIT2-UNIT3-...-UNIT8 the  units MUST not exceed 8: ")
String studentsInput = new Scanner(System.in).nextLine( );
String inputParts [ ]  = studentsInput.split( " ") ;
/*campus, regNumber units and unitCodes [ ] were  declared as instance fields somewhere up there ^ /*
campus = inputParts[ 0 ]; 
regNumber = inpuParts[ 1 ];
units = inputParts[ 2 ] ;
Since units is our point of interest here, i'll ignore the rest.So the units is something like SMA100-SCH300-SBC400-SPH100-SCH200 .I further split the units with '-' as the delimiter,
Code:
unitCodes  = units.split ( "-") ;
Now I have the students campus, regNumber and an array of unitCodes the student wishes to register, just what the function below
Code:
 registerUnits (String _campus, String _regNumber, String _unitCodes [] )
needs, so I call the function and passes the parameters to it, and the rest is up to me.Now here is what you might be up to,Apparently the function registerUnits( ) { } does everything right and now I have to tell the student that the unit registration was successful.I can easily do that, with ...
Code:
System.out.println(regNumber+": You successfully registered  "+unitCodes.length +" units.");
However, I would really appreciate listing the units in a coma separated list, so I worked this out but it just isn't taking me nowhere,

Code:
for(int i = 0;i<unitCodes.length;i++)
       String  registeredUnits = unitCodes[ i ]+",";
then i would append the registeredUnits to the message that I would tell the student
Code:
System.out.println("You successfully registered the units: "+registeredUnits+".Thanks for using this service.");
But like I said the output of the above isn't the best several modifications have just appended either the first unit (unitCodes[ 0 ]") or the first and the last (unitCodes[unitCodes.length]) units to the output,which isn't encouraging to a young programmer.Anyone with a better idea on how I would go about this?

Last edited by nmvictor; 11-21-2009 at 01:05 PM.
Bookmark Post in Technorati
  #2 (permalink)  
Old 11-21-2009, 05:47 PM
Senior Member
 
Join Date: Sep 2009
Location: Sweden/Borås
Posts: 107
Rep Power: 0
ocean is on a distinguished road
Default
Oo you double posted =) Still missing { } on the loop =) dont you?
Bookmark Post in Technorati
  #3 (permalink)  
Old 11-22-2009, 06:24 PM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 7,256
Rep Power: 11
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Default
Please don't post the same question more than once next time, even in different sub-forums.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
Someone helped you? their helpful post.
Help:Forums FAQ|How To Ask Questions The Smart WayResources:The Java Tutorials|Glossary for Java|NetBeans IDE|Sun DownloadsWeb:WritOnceTips:Is your IDE the best?|Which Application Server?
Bookmark Post in Technorati
Closed Thread

Bookmarks

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

BB 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
How to display the elements of a List as the values of a map? trueblue New To Java 27 08-27-2009 04:05 PM
Retrieve values of Text boxes using LIST Kayal Web Frameworks 2 03-20-2009 12:00 PM
List in Combobox database values Glouze Advanced Java 1 01-16-2009 06:26 PM
trying to set() values of in list of arraylist alvations New To Java 15 10-13-2008 10:35 PM
Getting values of an Option List mutuah Advanced Java 0 08-07-2007 04:42 AM


All times are GMT +2. The time now is 04:36 PM.



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