-
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 #5254 from devjonramos/main
Reto #39 - Java
- Loading branch information
Showing
1 changed file
with
38 additions
and
0 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
Retos/Reto #39 - TRIPLES PITAGÓRICOS [Media]/java/DevJonRamos.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,38 @@ | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class DevJonRamos { | ||
|
||
public static List<List<Integer>> triplesPitagoricos(int limite){ | ||
|
||
int m = 2; | ||
List<List<Integer>> ternas = new ArrayList<>(); | ||
|
||
while (true) { | ||
|
||
for (int n = 1; n < m; n++) { | ||
|
||
int a = (m * m) - (n * n); | ||
int b = 2 * m * n; | ||
int c = (m * m) + (n * n); | ||
|
||
if(c > limite) return ternas; | ||
|
||
ternas.add(List.of(a, b, c)); | ||
|
||
} | ||
|
||
m++; | ||
|
||
} | ||
|
||
} | ||
|
||
public static void main(String[] args) throws Exception { | ||
|
||
int limite = 50; | ||
|
||
System.out.println(triplesPitagoricos(limite)); | ||
|
||
} | ||
} |