QN013. Write a program to print prime numbers between 1 to 100.
1. Objective
To print the prime numbers between 1 to 100.
2. Theory
To achieve the result we use for loop to generate numbers between 1 to 100. For the calculation of prime number we use modulo(%) operator inside the if statement.
3. Source Code
      public class Qn013{  
        public static void main(String[] args){
          int number;
          for(number=1; number<=100; number++) 
          {
            int count=0;
            for(int i=2; i<=number/2; i++)
            {
              if(number%i==0)
              {
                count++;
                break;
              }
            }
            if(count == 0 && number != 1)
              System.out.print(number + "\t");
          } 
        }
      }
    
    4. Output
2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97
5. Conclusion
In this way, I would like to conclude that, we can get prime numbers between 1 to 100 by using for loop and some conditions.