Search code examples
javaloopscounter

Why is my integer variable count not incremenating and adding by 1 in for loop


(https://i.sstatic.net/kjquh.png)

Trying to increment the integer variable by count each time the if condition returned true.

it is not working properly the count is showing zero at all times

i am trying to find the program for prime number using loop


Solution

  • Change the if condition or statement from if(i%num == 0) to if(num%i == 0). It will lead to correct output. In our case input is number 10 it is divisible by number 2 and number 5. Then the program will print 10 is not an prime number.