class apmodulus
{
public static void main (String arg[])
{
int a=15,b;
b=a%5;
if (b==0)
System.out.println ("\n\t Divisible by 5 ");
else
System.out.println ("\n\t Not divisible by 5 ");
}
}
Note:
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