Search This Blog

If you have any problem or question please write in the comments. We will try to solve and send you the solution. Not just that we will also post your problems solution on our blog.

Monday, 13 June 2011

Using modulus or '%' operator in java program

class apmodulus
public static void main (String arg[])
int a=15,b;
if (b==0)
System.out.println ("\n\t Divisible by 5 ");
System.out.println ("\n\t Not divisible by 5 ");

          Modulus operator returns remainder. In the above program variable 'a' will be divided by 5. If 5 divides 'a' properly (with out returning any decimal answer) then the message "Divisible by 5" will be showed otherwise statement associated with 'else' will be executed.

No comments:

Post a Comment