English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

What does this function "%" do in JAVA? I know it some sort of mathematical function but I am completely confused by it. I am beginner at JAVA so please explain and use an example if you can.

2006-06-20 08:27:34 · 5 answers · asked by quackerjackets 1 in Computers & Internet Programming & Design

5 answers

The modulus, or the remainder.

For example, 32 % 10 is 2, the remainder if you divide 32 by 10. 8 % 3 is 2.

One great way to find out if an integer divides evenly is to check the modulus and find out if it's zero. So if X % Y is zero, X is divisible by Y. Let's say you have a four-digit year and want to display the last two digits. In the early days of programming you could say "year - 1900" but that stopped working after Y2K and was one of the sources of Y2K bugs. 2006 comes out as 106, not 06. But "year % 100" gives the right answer.

Good luck.

2006-06-20 08:42:24 · answer #1 · answered by Mantis 6 · 2 0

Hope this helps. It is the same as Java except use System.out.println() instead of the printf() statements.

2006-06-20 15:44:05 · answer #2 · answered by Anonymous · 0 0

I beleive it determines the remainer of devision between two integers.

2006-06-20 15:29:46 · answer #3 · answered by Anonymous · 0 0

It's the modulous operatior and gives you the remainder when you do division.

2006-06-20 18:11:27 · answer #4 · answered by brownfreckles1977 2 · 0 0

go ask a computer geek.

2006-06-20 15:36:03 · answer #5 · answered by Anonymous · 0 0

fedest.com, questions and answers