File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

variable returns "null" value in output

 
Kirstie Fran
Ranch Hand
Posts: 33
Android Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"c", from line 36, returns "null" as its value each time.
What could i have done wrong?
p.s.:And if you can, let me know of a way to remove a card after drawing it.




Output: "Card 1 null"
 
Rupesh Mhatre
Ranch Hand
Posts: 35
Eclipse IDE Hibernate jQuery
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kirstie Fran wrote:
public DeckOfCards() {
Deck = new Card[52];
for (int i = 0; i > 52; i++) {
deck[i] = new Card(i); //add a card to the deck

}
remaining = 52;
}


interesting mistake here it has to be i<52.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47229
52
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rupesh Mhatre wrote: . . . interesting mistake here it has to be i<52.
Actually you should avoid putting numbers into that part of a for loop. It should read i < deck.length.

You are reminded that when you create a new array of reference types, every element defaults to null.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic