Advertisement
MaTias0258

TPN0_4

Aug 31st, 2022
593
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.18 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class TPN0_4 {
  4.  
  5.     public static void main(String[] args) {
  6.         int cont=2,num=0;
  7.         boolean band=false;
  8.         try{
  9.             Scanner sc = new Scanner(System.in);      
  10.             System.out.println("Ingrese numero");
  11.             num = IngresoNumero();  
  12.             if(num % cont ==1) {
  13.                 System.out.println("El número " + num + " no es compuesto ");
  14.            }
  15.             while((cont < num) && !(band)) {
  16.                if(num % cont==0) {
  17.                  band=true;
  18.                  cont++;
  19.                  System.out.println("El número " + num + " es compuesto ");
  20.                }
  21.              }
  22.              }catch (Exception e){
  23.                 System.out.println("ERROR: El valor ingresado no es valido. Asegurese de ingresar solamente numeros");
  24.              }
  25.     }  
  26.  
  27.    
  28.     //Metodo para validar que los numeros ingresados sean validos.
  29.     static int IngresoNumero() throws Exception{
  30.         Scanner entrada= new Scanner(System.in);
  31.         int numero;
  32.         numero= entrada.nextInt();
  33.         if(numero<0) {
  34.             System.out.println("No es un numero positivo");
  35.         }
  36.         return numero;
  37.     }
  38.        
  39. }
  40.  
  41.  
  42.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement