+ 5

Whats wrong with my code...

Maybe something's wrong it does not work properly https://code.sololearn.com/cLLFnMFqRRR7/?ref=app

29th Aug 2019, 4:32 PM
Justin
Justin - avatar
3 Respuestas
+ 1
I'm replacing it with another variable but it is not working Please fix it for me
29th Aug 2019, 4:58 PM
Justin
Justin - avatar
0
the variable you use in the for-loop and the variable you incrment is the same
29th Aug 2019, 4:57 PM
Anton Böhler
Anton Böhler - avatar
0
import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int a=sc.nextInt(); boolean isPrime = true; for(int i=2;i<a;i++){ if(a % i == 0){ isPrime = false; break; } } if(isPrime){ System.out.println ("Prime"); } else{ System.out.println ("Not Prime"); } } }
29th Aug 2019, 5:04 PM
Anton Böhler
Anton Böhler - avatar