Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Random;
- import java.util.Scanner;
- public class Ejercicio_03 {
- public static void main(String[] args) {
- Helper obj = new Helper();
- Scanner entrada = new Scanner(System.in);
- Random aleatorio = new Random();
- int num = 0;
- int opc = obj.getInteger(entrada,
- "Elija la opcion de ingreso de datos:\n1 = Manual" + "\n2 = Aleatorio" + "\n ");
- switch (opc) {
- case 1:
- do {
- num = obj.getInteger(entrada, "Ingrese un Numero Positivo: ");
- } while (num < 0);
- break;
- case 2:
- num = aleatorio.nextInt(20);
- System.out.println("Numero Aleatorio: " + num);
- }
- System.out.println("¿El numero es PERFECTO, ABUNDANTE O DEFICIENTE? ");
- validarPerfecto(num);
- validarAbundante(num);
- validarDeficiente(num);
- }
- public static void validarPerfecto(int n) {
- int suma = 0;
- for (int i = 1; i < n; i++) {
- if (n % i == 0) {
- suma += i;
- }
- }
- if (suma == n) {
- System.out.println("¡¡¡ES UN NUMERO PERFECTO!!!");
- } else {
- System.out.println("no es perfecto");
- }
- }
- public static void validarAbundante(int n) {
- int suma = 0;
- for (int i = 1; i < n; i++) {
- if (n % i == 0) {
- suma += i;
- }
- }
- if (suma > n) {
- System.out.println("¡¡¡ES UN NUMERO ABUNDANTE!!!");
- } else {
- System.out.println("no es abundante");
- }
- }
- public static void validarDeficiente(int n) {
- int suma = 0;
- for (int i = 1; i < n; i++) {
- if (n % i == 0) {
- suma += i;
- }
- }
- if (suma < n) {
- System.out.println("¡¡¡ES UN NUMERO DEFICIENTE!!!");
- } else {
- System.out.println("no es deficiente");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment