• Post Reply Bookmark Topic Watch Topic
  • New Topic

% in java  RSS feed

 
Stacey Jurgens
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please explain what % means in java and provide a few examples.... the question I am looking at is ( 1415/ 100 ) * 60 + ( 1415 % 100 )

also, please explain the difference between / and % in java

Thanks for your input
 
Neeraj Dhiman
Ranch Hand
Posts: 68
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"%" is Modulus operator in java which give the remainder of division.
"/" is the division.

e.g. 1415/100 results 14.15 and 1415 %100 gives you 15 i.e is is remainder.
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Neeraj Dhiman wrote:e.g. 1415/100 results 14.15

No. the result of dividing two ints is an int. Any fractional part is truncated.

The result of 1415/100 is 14.
 
Neeraj Dhiman
Ranch Hand
Posts: 68
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes, Darryl the result is definitly truncated in this expression.
It was just to show the exact difference between / and %. Thats only the reason i wrote 14.15.Sorry for that and thanks.
 
Stacey Jurgens
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you both for your input. Starting out in Java is very daunting .... places like this offer so much to newbies like me.

Thank you for taking the time to answer my question

Take care
 
Campbell Ritchie
Marshal
Posts: 56527
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You will find about operators here, or here. The first link should be easier to read.

Even though it is confusing about unary + and uses the wrong name for && and || on one page (the right name, Conditional..., appears elswhere).
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!