I'm trying to print all the prime numbers between 2 and 100, but I am getting only 2 and 3.
I've tried every possible alternative, and it comes up with different error or different output.
public static void main(String[] args) {
    boolean flag = true;
    for (int i = 2; i <= 100; i++) {
        for (int j = 2; j < i; j++) {
            if (i % j == 0) {
                flag = false;
                break;
            }
        }
        if (flag) {
            System.out.println(i);
        }
    }
}
I don't need any alternative way, I just want to know what's happening in my code and why it gives only 2 and 3?
 
     
     
    