Software & Finance





Java Display the numbers containing the digit '5' in between 100 to 200





 

I have given here Java code to Display the numbers containing the digit '5' in between 100 to 200. The idea here is to use the mod and divide operator to get the single digit and check whether it is equal to 5 or not.

 

 

Source Code


import java.lang.*;

import java.util.*;

import java.io.*;

 

 

class SumExample

{

   public static void main(String[] args)

   {     

      int sum = 0;

      int i, a, b, c;

      for(i = 100; i <= 200; i++)

      {

         a = i % 100;

         b = a / 10;

         c = a % 10;

         if(b == 5 || c == 5)

            System.out.format("%d\n", i);

         sum += i;

      }

      System.out.format("\n\nSum = %d\n\n", sum);

   }

}

Output


105

115

125

135

145

150

151

152

153

154

155

156

157

158

159

165

175

185

195

 

Sum = 15150