Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
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 09-12-2008, 06:23 PM
Member
 
Join Date: Sep 2008
Posts: 19
nishant is on a distinguished road
help
here is my code ...could u please solve this issue. i have a problem while using the deck.length.



public static void cardList(int numHands,int cardsPerHand){
List<String> deck,hand;
//52-card deck

String[]suit=new String[]{"S","H","D","C"};
String[] rank=new String[]{"A","2","3","4","5","6","7","8","9","10","J","Q", "K"};

deck=new ArrayList<String>();
for(int i=0;i<deck.length; i++){
for(int j=i;j<deck.length;j++){
deck.add(rank[i]+"-"+suit[j]);
}
}

Collections.shuffle(deck);//shuffles the heap of the crads

//dealing the cards
for(int i=0;i<numHands;i++){
hand=deck.subList(deck.size()-cardsPerHand,deck.size());
System.out.println(hand);
//hand.clear();//removes the sub-list from the list
}}}
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 09-12-2008, 09:49 PM
Senior Member
 
Join Date: Jun 2008
Posts: 551
masijade is on a distinguished road
Read the API docs for ArrayList and tell me whether or not there is a length field in that Class, and what the method is that you should use instead.

ArrayList (Java Platform SE 6)

Edit: Besides, shouldn't you be using suit and rank instead? At that point, since you've just created it, the ArrayList is empty.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 09-23-2008, 03:14 PM
Member
 
Join Date: Aug 2008
Posts: 13
satu is on a distinguished road
replace your code with this....

String[]suit=new String[]{"S","H","D","C"};
String[] rank=new String[]{"A","2","3","4","5","6","7","8","9","10","J"," Q", "K"};

deck=new ArrayList<String>();
for(int i=0;i<rank.length; i++){
for(int j=i;j<suit.length;j++){
deck.add(rank[i]+"-"+suit[j]);
}
}

before adding any element List is empty and not work for you here..
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



All times are GMT +3. The time now is 10:08 AM.


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