0
I wanna know what numbers are prime before num10 and entered by user with java language
My attempt public class Randam { static int limit; static boolean flag; public static void main(String[] args) { Scanner r = new Scanner(System.in); System.out.println("enter your limit"); int rez=r.nextInt(); for(int i=2;i<limit;i++) { if(limit%2==0) System.out.println("not primre"); } for(int i=0;i<=limit;i++) flag=flag(i); System.out.print(i);
2 Réponses
+ 2
// Hope this code helps you
public static boolean isPrime(int num)
{
for (int i=2; i<num; i++) if (num %i == 0) return false;
return true;
}
public static void main(String[] args) {
for(int i=2; i<=10; i++) if (isPrime(i)) System.out.print(i + " ");
}
https://code.sololearn.com/cl4R5NT4Vjkl
+ 2
loop through numbers then check if they are prime