Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package tp0nuevo;
- import tp0.Helper;
- public class Tp0ejercicio4 {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- System.out.println("Ejercicio 4 Tp 0");
- System.out.println("Veamos si un número es compuesto");
- if (esCompuesto(ingresarNumero())) {
- System.out.println("Su número es compuesto");
- }else {
- System.out.println("Su número es primo");
- }
- System.out.println("Fin del programa");
- }
- @SuppressWarnings("static-access")
- public static Integer ingresarNumero() {
- Helper help = new Helper();
- int parametro = help.getPositiveInt("Ingrese un número entero positivo para continuar ");
- return parametro;
- }
- public static boolean esCompuesto(int a) {
- int contador = 0;
- int i = 2;
- while(i<=(Math.sqrt(a))) {
- if (a%i==0)contador++;
- i++;
- }
- if (contador>0) return true;
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement