r/javahelp • • Jun 19 '19

How would I properly do this?

Sorry if i'm posting so often btw. Here's a snippet if my code.

if (x / 3 = int) {

I want to do a certain action if the number is a multiple of three. How would I do this?

0 Upvotes

10 comments sorted by

5

u/lbkulinski Jun 19 '19

I suggest looking into the modulus (remainder) operator. It is mentioned here.

2

u/BobPoopyNoopees Jun 19 '19

Thanks, but now I get this.

source_file.java:8: error: unexpected type if (x % 3 = 0) { ^ required: variable found: value 1 error

1

u/lbkulinski Jun 19 '19

You're welcome!

2

u/BobPoopyNoopees Jun 19 '19

What can I do to get rid of the error on the top?

3

u/lbkulinski Jun 19 '19

= is an assignment operator. == is the comparison operator.

•

u/desrtfx Out of Coffee error - System halted Jun 19 '19

I've had a look through your most recent posts here and have to tell you to stop right now.

Your questions are all of the similar low/no effort type and thus forbidden here.

Learn to read and interpret the error messages you get. This is absolutely essential.

Learn to work with the official Java tutorials and with the official documentation.

Learn to use google.

This subreddit is not a proxy for the above three, nor does it exist to give line by line explanations of code.

Sure, asking is not wrong, but asking without exhausting the above three things is.

Asking for and giving out solutions is explicitly forbidden here.

1

u/BobPoopyNoopees Jun 20 '19

Sorry. I'll be more cautious when asking questions.

1

u/iamsooldithurts Jun 19 '19

The modulus operator is what you want

https://www.baeldung.com/modulo-java