• Post Reply Bookmark Topic Watch Topic
  • New Topic

declaring parameters  RSS feed

 
Pat Steele
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a question from my beginning JAVA course. I want to have parameters that I use the "void" for, in other words it doesn't return anything.

 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pat Steele wrote:I want to have parameters that I use the "void" for, in other words it doesn't return anything.

Can you explain in more detail what exactly you mean?

The keyword void is used when you declare a method, to indicate that the method does not return any value. In the code that you have posted there are two void methods, named go and takeTwo.

The method go doesn't have any parameters, and the method takeTwo has two parameters which are both of type int.

If you want a method to return a value (rather than no value), then you should replace the void in the method declaration by the type of the value that the method should return, and you'll need to have a return statement in the method with the value to return.

See Defining Methods in Oracle's Java Tutorials for more details on how to define methods, and specifically Returning a Value from a Method to learn how to return a value from a method.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!