Advertisement
Guest User

Untitled

a guest
Mar 17th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. public class Primes
  2. {
  3. static String res="";
  4. static int cnt=0;
  5. public static void Primes(int p)
  6. {
  7. if(p<2)
  8. {
  9. System.out.println("Veuillez saisir un entier >=2");
  10. }
  11. else
  12. {
  13. for(int j=2;j<=p;j++)
  14. {
  15. for(int i=1;i<=j/2;i++)
  16. {
  17. if(j%i==0)
  18. {
  19. cnt+=1;
  20. }
  21. }
  22.  
  23. if(cnt==1)
  24. {
  25. res+=j+" ";
  26.  
  27. }
  28. cnt=0;
  29. }
  30. System.out.println("resultat :"+res);
  31.  
  32. }
  33. }
  34. public static void main(String arg[])
  35. {
  36. Primes(19);
  37. //System.out.println(5%2);
  38.  
  39. }
  40.  
  41.  
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement