Prime Numbers

Given a starting number and the ending number the task is to find the all the Prime Number present in that given range and also to display it’s frequency.

Prime Number is a number which is only divisible by 1 and the number itself i.e., it has no factors other than 1 and itself.

Example 1: 7 is only divisible by 1 and itself only. Hence it is a Prime Number.

Example 2: 4 is divisible by 1 and 2 and 4. Hence it is not a Prime Number.

Java
import java.util.*;
public class PrimeNumberRange
{
    public static void main(String args[])
    {
        int start=0,end=0,flag=0,frequency=0;
        Scanner sc=new Scanner(System.in);
        System.out.print("Enter a starting range: ");
        start=sc.nextInt();
        System.out.print("Enter a ending range: ");
        end=sc.nextInt();
        System.out.println("Prime Numbers in the given range are:-");
        for(int i=start;i<=end;i++)
        {
            for(int j=1;j<=i;j++)
            {
                if(i%j==0)
                {
                    flag++;
                }
            }
            if(flag==2)
            {
                System.out.println(i);
                frequency++;
            }
            flag=0;
        }
        System.out.println("Frequency: "+frequency);
    }
}
Java