+ 6
My program is resulting in an error. This is to generate prime numbers.Please tell my error.
import java.util.Scanner; public class Program{ public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); for(int i = 1; i <= n; i++){ int c = 0; int s = i; for(int j = 1; j <= i; j++){ if(s % j = 0){ c += 1; } } if(c == 2){ System.out.println(i); } } } }
3 Respostas
+ 8
Hi Saswata Biswas,
In if (s % j = 0), you have not made a 2 sign equals (==)
Correction : if (s % j == 0)
+ 6
Thank you. Zohir
0
Yeah. Tip: one is neither prime nor composite😊