Natural number divisible by 5 || for loop || java programs || Java


In this, we are going to write a simple program for sum of all 3 digit odd natural numbers divisible by 5 in Java.



class Sum
{
  public static void main(String[] args)
  {
    int i,s=0; for(i=101;i<=999;i+=2)
    {
        if(i%5==0)
        {
            s+=i;
        }
    }
    System.out.print("Sum= "+s);
  }
}
  

#ENJOY CODING

Post a Comment

FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP

Previous Post Next Post