From 647f231020d4238ba711e2db18153fd232aaeadc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vi=CC=81ctor=20Andre=CC=81s?= <102297884+vandresca@users.noreply.github.com> Date: Sun, 30 Jul 2023 02:39:59 +0200 Subject: [PATCH] Reto #4 - Primo, Fibonnaci, Par --- .../java/vandresca.java | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 Retos/Reto #4 - PRIMO, FIBONACCI Y PAR [Media]/java/vandresca.java diff --git a/Retos/Reto #4 - PRIMO, FIBONACCI Y PAR [Media]/java/vandresca.java b/Retos/Reto #4 - PRIMO, FIBONACCI Y PAR [Media]/java/vandresca.java new file mode 100644 index 0000000000..fbd3ae6368 --- /dev/null +++ b/Retos/Reto #4 - PRIMO, FIBONACCI Y PAR [Media]/java/vandresca.java @@ -0,0 +1,60 @@ +package Reto5; + +import java.util.InputMismatchException; +import java.util.Scanner; + +/* + * Escribe un programa que, dado un número, compruebe y muestre si es primo, + * fibonacci y par. + * Ejemplos: + * - Con el número 2, nos dirá: "2 es primo, fibonacci y es par" + * - Con el número 7, nos dirá: "7 es primo, no es fibonacci y es impar" + */ +public class vandresca { + + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + int input; + try{ + input = scanner.nextInt(); + System.out.println(makeMessage(input)); + }catch(InputMismatchException ime){ + + }finally{ + scanner.close(); + } + } + + private static String makeMessage(int input){ + StringBuilder message = new StringBuilder(); + message.append(String.valueOf(input)); + message.append(isPrime(input)); + message.append(isFibonnaci(input)); + message.append(isEven(input)); + return message.toString(); + } + + + private static String isPrime(int number){ + for(int i=2; i