Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class TPN0_4 {
- public static void main(String[] args) {
- int cont=2,num=0;
- boolean band=false;
- try{
- Scanner sc = new Scanner(System.in);
- System.out.println("Ingrese numero");
- num = IngresoNumero();
- if(num % cont ==1) {
- System.out.println("El número " + num + " no es compuesto ");
- }
- while((cont < num) && !(band)) {
- if(num % cont==0) {
- band=true;
- cont++;
- System.out.println("El número " + num + " es compuesto ");
- }
- }
- }catch (Exception e){
- System.out.println("ERROR: El valor ingresado no es valido. Asegurese de ingresar solamente numeros");
- }
- }
- //Metodo para validar que los numeros ingresados sean validos.
- static int IngresoNumero() throws Exception{
- Scanner entrada= new Scanner(System.in);
- int numero;
- numero= entrada.nextInt();
- if(numero<0) {
- System.out.println("No es un numero positivo");
- }
- return numero;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement