This week's book giveaway is in the OCP forum.
We're giving away four copies of OCP Java SE 8 Programmer II Exam Study Guide and have Kathy Sierra, Bert Bates, & Elizabeth Robson on-line!
See this thread for details.
Win a copy of OCP Java SE 8 Programmer II Exam Study Guide this week in the OCP forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

% in java  RSS feed

 
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
 
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.
 
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
 
Marshal
Posts: 58415
178
  • 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).
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!