Saturday, January 10, 2015

Finding the remainder using java program


The java program given below will find out the remainder after dividing 5 by 2. The remainder will be calculated using the sixth line r=a%b; and the result will be stored into the variable r. Later the result will be displayed using the eighth line System.out.println("Remainder is="+r);

public class Remainder{
  public static void main(String [] args){
  //declaring variables
  int a=5, b=2, r=0;
  //operation to find out the remainder
  r=a%b;
  //printing the remainder stored in the variable r
  System.out.println("Remainder is="+r);
 }
}

Let's do the same program in different way

No comments:

Post a Comment