• Post Reply Bookmark Topic Watch Topic
  • New Topic

Trouble passing parameters  RSS feed

 
Jacob Pager
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For some reason, when I test out my code, my randomly generated numbers don't appear. Here is a sample result:

> What do you want to generate, integer, double, or character?

>integer

>What is the upper limit and lower limit of the integers you want to generate?

>1

>10

>How many integers do you want to generate?

>10

>BUILD SUCCESSFUL (total time: 9 seconds)

Is this because my code is not passing my parameters correctly? I'm not sure how to fix this either.

Here is my code for reference (it's not completed at the moment)
 
Carey Brown
Saloon Keeper
Posts: 3329
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the output that you are getting? Where did "BUILD SUCCESSFUL" come from when you run the program?
 
Carey Brown
Saloon Keeper
Posts: 3329
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


You might try this.
 
Jacob Pager
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That just means that there are no problems with the program, and that it has terminated.

Carey Brown, it says I need to import a Random.util, but when I do that, I just get another error message.
 
Carey Brown
Saloon Keeper
Posts: 3329
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In your example run you are entering '1' for the upper limit and '10' for the lower limit, this is backwards.
 
Carey Brown
Saloon Keeper
Posts: 3329
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jacob Pager wrote:That just means that there are no problems with the program, and that it has terminated.

Carey Brown, it says I need to import a Random.util, but when I do that, I just get another error message.


What is the error exactly? Yes, you will need to import "java.util.Random".
 
Jacob Pager
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Carey Brown:

It is "non static method nextInt(int) cannot be referenced from a static context"
 
Carey Brown
Saloon Keeper
Posts: 3329
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


My bad.
 
Jacob Pager
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It still doesn't give me any numbers as an output
 
Carey Brown
Saloon Keeper
Posts: 3329
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you re-post your code as it stands now? Also, what input are you giving it? Did you resolve the 1 vs 10 being backwards issue?
 
Paul Clapham
Sheriff
Posts: 22838
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code you originally posted doesn't ever call that method, as far as I can see. (Correct me if I'm wrong.) So you shouldn't be surprised that you don't get any output from it.
 
Carey Brown
Saloon Keeper
Posts: 3329
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't see where you are actually calling random(int,int,int).
 
Jacob Pager
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
see thats what im confused about.

1 10 issue was not fixed yet.





 
Jacob Pager
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have to go now, I'll talk to you in about 8 hours, gtg to sleep, sry
 
Carey Brown
Saloon Keeper
Posts: 3329
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jacob Pager wrote:see thats what im confused about.

1 10 issue was not fixed yet.


Well, you have a couple of choices:
1) enter the values as: 10 1
2) swap the variables and prompts for lower and upper bounds
3) check to see if user entered them in backwards and quietly swap the values
 
Paul Clapham
Sheriff
Posts: 22838
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you get back to it, I would suggest looking at the comment at line 51 of your latest post. It's unfortunately a lie... no parameters are being passed to any method in the vicinity of that comment. Go back and have a look at your textbook, or whatever learning materials you're working from, and find out how to call a method.
 
Jacob Pager
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, so I have an update on my code, but I am getting this error message:

Illegal static declaration in inner class NewNumberCharacter.RandomDataGenerator
modifier 'static' is only allowed in constant variable declarations

What does this mean? How do I fix this?




 
Carey Brown
Saloon Keeper
Posts: 3329
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jacob Pager wrote:Ok, so I have an update on my code, but I am getting this error message:

Illegal static declaration in inner class NewNumberCharacter.RandomDataGenerator
modifier 'static' is only allowed in constant variable declarations

What does this mean? How do I fix this?


From Eclipse: The method random cannot be declared static; static methods can only be declared in a static or top level type.
Therefore remove the word static in front of your methods.
 
Carey Brown
Saloon Keeper
Posts: 3329
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Carey Brown wrote:
Jacob Pager wrote:Ok, so I have an update on my code, but I am getting this error message:

Illegal static declaration in inner class NewNumberCharacter.RandomDataGenerator
modifier 'static' is only allowed in constant variable declarations

What does this mean? How do I fix this?


From Eclipse: The method random cannot be declared static; static methods can only be declared in a static or top level type.
Therefore remove the word static in front of your methods.


I take that back. Your RandomDataGenerator class should not be contained inside your NewNumberCharacter class. However, for this to work you must remove the word 'public' from in front of your RandomDataGenerator class.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!