wood burning stoves 2.0
The moose likes Beginning Java and the fly likes Dereferencing error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Dereferencing error" Watch "Dereferencing error" New topic

Dereferencing error

Nicole Doetsch

Joined: Feb 22, 2012
Posts: 6
I keep getting a dereferencing error on a program that I have to write pertaining to the "Birthday Paradox"

I understand that int is a primitive type, but I'm not sure how to make it dereferencable.

My code is below and I hope someone could help me clear up this problem!

Ralph Cook
Ranch Hand

Joined: May 29, 2005
Posts: 479
You cannot dereference a primitive type. Whatever code you wanted to be run as your method isDuplicate(), it cannot be a method on int.

Perhaps what you meant to do was calculate a birthdate and store it in a separate int variable, then determine if the array at that int position had already been visited.
dennis deems
Ranch Hand

Joined: Mar 12, 2011
Posts: 808
Your code looks like it is trying to combine three different strategies into one procedure. You have an array birthDates of size 365 which suggests you mean each index to represent a day in the year. Then you pull this value named "people" out of thin air and use that as the array index. You randomly write an int value to the array. Then you call a method that takes no parameter and returns no value, but apparently is meant to evaluate whether the random value you just cooked up is a duplicate. However, it's actually looking at an element in the array and determining whether that element is equal to itself.

I recommend you use pencil and paper and work out how you would perform this task without a computer. You may actually have done so on the first day of a statistics course. Write out that process. Don't imagine you are writing instructions for a computer. Imagine you are writing instructions for a person to read. Write it out in simple language, so that someone could understand who had never taken statistics and doesn't know what the Birthday Paradox is. When you have a set of instructions so simple and exact that this is the case, you'll be ready to start writing code.
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46402
What’s the birthday paradox? Is it that you have a >50% chance of two people having the same birthday if you have a population of ≥23?
Consider Paul's rocket mass heater.
subject: Dereferencing error
It's not a secret anymore!