+ 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); } } } }

16th Dec 2018, 2:03 PM
Saswata Biswas
Saswata Biswas - avatar
3 Respuestas
+ 8
Hi Saswata Biswas, In if (s % j = 0), you have not made a 2 sign equals (==) Correction : if (s % j == 0)
16th Dec 2018, 2:07 PM
program
program - avatar
+ 6
Thank you. Zohir
17th Dec 2018, 4:59 AM
Saswata Biswas
Saswata Biswas - avatar
0
Yeah. Tip: one is neither prime nor composite😊
16th Dec 2018, 4:21 PM
Yash
Yash - avatar