| Author |
setting a variable with a random number
|
Jeff Ciaccio
Greenhorn
Joined: Nov 26, 2008
Posts: 25
|
|
I am trying to set variable "addr" to some random int, but I cannot seem to pass the random int in. Can anybody help me?
|
Jeff Ciaccio, Java novice <br />Physics and AP Physics Teacher<br />Sprayberry High School <br />Marietta, GA
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16686
|
|
This isn't valid Java. In a method declaration, the parameters are type and name of params -- you can't put method calls there.
Henry
|
Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
|
 |
Gavin Tranter
Ranch Hand
Joined: Jan 01, 2007
Posts: 333
|
|
Well first off, you are trying to execute a statement in a parameter:
This ising really going to work, firstly i could be wrong but its an illegal statement and secondly, even if it was legal randNum hasnt been initiallised:
So given that what do you think would help you to solve your problem?
|
 |
Fred Hamilton
Ranch Hand
Joined: May 13, 2009
Posts: 679
|
|
It's not clear to me how your setAddr and getAddr methods are being called.
However, if setAddr method just sets the value of the instance variable addr, then presumably getAddr is going to return the value of your instance variable to some other method or class. So shouldn't your getAddr() method just return addr, and not actually set its value a second time?
p.s. ok two people got in ahead of me as I was typing my note.
|
 |
Jesper de Jong
Java Cowboy
Bartender
Joined: Aug 16, 2005
Posts: 12909
|
|
Your main() method contains some strange things. For example, the following lines of code:
What do you think this code does, why have you included it? It does not "create variable names cpu0, cpu1, etc." as the comment says.
|
Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
|
 |
 |
|
|
subject: setting a variable with a random number
|
|
|