#Need some clarification

1 messages · Page 1 of 1 (latest)

wet briar
#

So this is an example from my professor of how to print prime numbers. Now, I have asked multiple people to explain to me how the public static works and none of them were able to explain to me properly which is wild.

I am asking anyone to tell me this one simple thing without being patronizing: what does int numberOfPrimes do in public static void printPrimeNumber . Please guide me this as much easy as you can I am so desperate and I hate how people just say “look it up" when it is not that easy, it really isn’t and I wish people can understand that. Sorry for ranting, but I am tired of being confused.

frozen wagonBOT
#

<@&987246399047479336> please have a look, thanks.

frozen wagonBOT
#

While you are waiting for getting help, here are some tips to improve your experience:

Code is much easier to read if posted with syntax highlighting and proper formatting.

If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.

Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.

south locust
#

method is a reusable piece of code

#

methods can have 0 or more arguments and either produce a result or not (void methods)

#

what you see is a method with a single argument numberOfPrimes of type int

#

public refers to code visibility and static indicates that your code doesn't belong to any particular object, when you're just starting learning java and not touching OOP all your stuff will be static

#

void is the return type (returns nothing)

#

the method that you have at the bottom returns a boolean for example

#

a true/false value

#

that method is also outside of a class so this code won't compile

#

@wet briar

#

simplest example would be just looking up methods in the Math class

#

like this one

#

you can write int max = Math.max(3, 5);

#

since this is a method that produces a result (int)

#

and so your variable max will hold the result of this method

#

whereas in your code the result of method printPrimeNumbers is not assigned to any variable, because there is no result (the method is void)

wet briar
#

Ahhh I see

#

Thank you so much !

wet briar
#

@south locust oh and one more question, so what does the int number does in the public static Boolean ?

south locust
#

it's an argument

#

if you want your method to check whether a number is prime, you must give it a number to check

#

otherwise, what number is it supposed to check

wet briar
#

I see, thanks!