-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5248 from sdesantiago/main
Reto #39 - Java
- Loading branch information
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
Retos/Reto #39 - TRIPLES PITAGÓRICOS [Media]/java/Sdesantiago.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
Crea una función que encuentre todos los triples pitagóricos | ||
(ternas) menores o iguales a un número dado. | ||
- Debes buscar información sobre qué es un triple pitagórico. | ||
- La función únicamente recibe el número máximo que puede | ||
aparecer en el triple. | ||
- Ejemplo: Los triples menores o iguales a 10 están | ||
formados por (3, 4, 5) y (6, 8, 10). | ||
* Triple pitagórico -> a² = b² + c² | ||
*/ | ||
|
||
import java.util.Scanner; | ||
|
||
public class Sdesantiago { | ||
public static void main(String[] args) { | ||
int entrada; | ||
|
||
Scanner scan = new Scanner(System.in); | ||
System.out.print("RETO 39 BY MOUREDEV\n- Ingresa un número positivo para comenzar: "); | ||
entrada = scan.nextInt(); | ||
scan.close(); | ||
if (entrada<=0) { | ||
System.err.print("ERROR: El valor ingresado no es válido. Finalizando ejecución del programa."); | ||
return; | ||
} | ||
for (int a=entrada;a>0;a--){ | ||
for (int b=a-1;b>0;b--){ | ||
for (int c=b;c>0;c--){ | ||
if (Math.pow(a,2)==Math.pow(b,2)+Math.pow(c,2)) | ||
System.out.println("("+a+","+b+","+c+")"); | ||
} | ||
} | ||
} | ||
} | ||
} |