RAUL-SUAREZ

Untitled

Aug 28th, 2021
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class punto4 {
  4.  
  5. public static void main(String[] args) {
  6.  
  7. Scanner num= new Scanner (System.in);
  8.  
  9. int x,contador=0;
  10.  
  11. System.out.println("Ingrese un numero positivo");
  12.  
  13. x=num.nextInt();
  14.  
  15. if (x>0) {
  16. for(int i=1;i<=x;i++) {
  17. if(x%i==0) {
  18. contador++;
  19. }
  20. }
  21. if(contador==2) {
  22. System.out.println("es primo");
  23. }
  24. else {
  25. System.out.println("no es primo");
  26. }
  27.  
  28. }
  29. else {
  30. System.out.println("el numero ingresado no es positivo");
  31. }
  32.  
  33.  
  34. }
  35.  
  36. }
Advertisement
Add Comment
Please, Sign In to add comment