0

Write a Program to print 15 Pythagoras Triplets.

Use three Loops(can be For)Innermost loop will have Break with label.Introduce label to the outermost loop to exit when ten triplets get printed.

14th Sep 2016, 8:25 PM
ASTHA SINGH
ASTHA SINGH - avatar
2 Respostas
+ 2
http://code.sololearn.com/cezMK9e2bD1R public class Program { public static void main(String[] args) { int count = 0; search: for (int c = 3; ; c++) { for (int b = 2; b < c; b++) { for (int a = 1; a < b; a++) { if (a*a + b*b == c*c) { System.out.println("(" + a + ", " + b + ", " + c + ")"); count++; if (count >= 15) { break search; } } } } } } }
14th Sep 2016, 8:51 PM
Zen
Zen - avatar
0
actually, there are only three pythagorean triplets in mathematics i.e 3, 4 and 5
18th Sep 2016, 7:38 AM
Andy
Andy - avatar