The moose likes Beginning Java and the fly likes variable returns Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "variable returns "null" value in output" Watch "variable returns "null" value in output" New topic

variable returns "null" value in output

Kirstie Fran
Ranch Hand

Joined: Feb 16, 2011
Posts: 33

"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

Joined: Apr 29, 2011
Posts: 35

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

Joined: Oct 13, 2005
Posts: 46367
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.
I agree. Here's the link:
subject: variable returns "null" value in output
It's not a secret anymore!