Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

setting a variable with a random number

 
Jeff Ciaccio
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?

 
Henry Wong
author
Marshal
Pie
Posts: 20892
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
 
Gavin Tranter
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 684
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Saloon Keeper
Posts: 15207
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic