The Artima Developer Community
Sponsored Link

Java Buzz Forum
Modulo or Remainder Operator in Java

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Javin Paul

Posts: 1090
Nickname: javinpaul
Registered: Jan, 2012

Javin Paul is Java Programmer working on Finance domain.
Modulo or Remainder Operator in Java Posted: Nov 18, 2014 8:31 AM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by Javin Paul.
Original Post: Modulo or Remainder Operator in Java
Feed Title: Java67
Feed URL: http://www.java67.com/feeds/posts/default?alt=rss
Feed Description: Java and technology tutorials, tips, questions for all programmers.
Latest Java Buzz Posts
Latest Java Buzz Posts by Javin Paul
Latest Posts From Java67

Advertisement
Modulo Operator is one of the fundamental operator in Java. It's a binary operator i.e. it require two operands. In a division operation the remainder is returned by using modulo operator. It is denoted by % (percentage) sign. For example 5%2 will return 1 because if you divide 5 with 2, remainder will be 1. For a programmer it's very important to know how to use this operator, they are very important to build logic. For example, in many cases like reversing a number or checking if a number is palindrome, you can use modulus operator with 10 to get the last digit, for example 101%10 will return 1 or 1234%10 will return 4, the last digit. It is one of the rather less used arithmetic operator in comparison of +, -, * and /. One of the important point about the remainder operator which is not know by many Java programmer is that it can also be used with floating point numbers. It's surprising because you don't normally think of real number division as producing remainders. However there are some times when it's useful to ask exactly how many times does 2.5 go into 7.5 and what's left over? The answer is that 2.5 goes into 7.5 three times with zero left over, and it's that zero which is the result of 7.5 % 2.5 in Java. Another good use of modulus operator is to check if a number is even or odd. In case of even number, number%2 will return 0, while if a number is odd then number%2 will return 1.
Read more »

Read: Modulo or Remainder Operator in Java

Topic: Java : Collection Framework : Deque (Element & Peek Methods) Previous Topic   Next Topic Topic: FORTH language processor on comet

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use