Question:
How do you get the remainder in division for Java? In other words how would you write that down in code?
shadowpal2
2007-10-15 09:31:03 UTC
Yea i just want the remainder. The division is going to be something like y/19. The variable y is actually going to be whatever the user inputs when constructing the object year. But again all I'm looking for is how to write in code to get only the remainder. Also how can i just get the quotient and not the remainder? It's not really a math question, just a question on how to write it in Java.
Eight answers:
thisguy
2007-10-15 09:43:36 UTC
For the remainder, use y%19. % is the modulus operator and will divide y by 19, then return the remainder.



int x = y % 19;



To get the full value, you could use the round function:



int x = Math.round((y/19));



but that will round the number which could make it larger and that might not be what you.



Another option would be



int x = (y/19)-((y%19)/19);



This would find the actual value of the division, then subtract the remainder from that value to give you the whole number
anonymous
2015-08-16 23:39:23 UTC
This Site Might Help You.



RE:

How do you get the remainder in division for Java? In other words how would you write that down in code?

Yea i just want the remainder. The division is going to be something like y/19. The variable y is actually going to be whatever the user inputs when constructing the object year. But again all I'm looking for is how to write in code to get only the remainder. Also how can i just get the...
?
2016-12-18 19:30:15 UTC
Java Remainder
Mr. Scientist
2007-10-15 09:40:38 UTC
The remainder of division is provided by the Modulus operator. It is usually the % sign.



5 / 2 = 2.5



5 % 2 = 1



To get just the quotient, just shove the answer into an integer variable rather than a double to chop off the decimal remainder.
moskos
2016-10-01 05:47:51 UTC
Java Division
?
2016-04-08 09:45:06 UTC
For the best answers, search on this site https://shorturl.im/awhWl



It's called the modulo operator (%). This expression: int foo = 99 % 10; Calculates the remainder of 99 divided by 10 (and places it in foo). It's a common operator in most computer programming languages (C, C++, C#, Java, etc.). HTH
Patricia
2016-03-18 04:03:33 UTC
Jeez, there sure are some esoteric and asinine over-analytical answers above. A word is a word, whether spoken or written. When written, it is not an artistic representation of the word -- it's just the word, in basic written communication. However, if someone were to write the word in artistically creative lettering that emphasized what the word meant, it would then be both a word and a graphic -- even art. But never a "picture" or other kind of representation or documentation.
Smacks!!!!!
2007-10-15 09:39:29 UTC
There is an operator called the modulus operator (the '%' character), which returns the remainder of dividing one number into another. IE,



int a = 20;

int b = 15;

int r = a % b; // r gets 5.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...