
-----------------------------------
xanderman2113
Mon Nov 10, 2014 12:17 pm

Any help with this grade 11 program relating to Pythagorean Triplets?
-----------------------------------
I am having some trouble wrapping my head around this question. We are asked to do full documentation beforehand, but sometimes coding first helps me. Any ideas are greatly appreciated.

We are using BlueJ 1.3.5

Thanks!

Three positive integers a, b, and c with a < b < c form a Pythagorean
triplet if a2 + b2 = c2. For example, 3, 4, and 5 form a Pythagorean
triplet since 32 + 42 = 52. Write a program that first prompts the
user for a positive integer and then finds and prints all Pythagorean
triplets whose largest member is less than or equal to that integer.

-----------------------------------
williamd
Mon Nov 10, 2014 12:47 pm

RE:Any help with this grade 11 program relating to Pythagorean Triplets?
-----------------------------------
yes

-----------------------------------
Insectoid
Mon Nov 10, 2014 12:54 pm

RE:Any help with this grade 11 program relating to Pythagorean Triplets?
-----------------------------------
Basically you're just tossing some equations into a nested for loop. Should look something like this:

[code]
for (int c = ?; ??; ??) {
    for (int b = ?; ??; ??){
        for (int a = ?;??; ??){
            //check if a, b, c satisfy requirements and print
        }
    }
}[/code]

Replace the ??s with code that will makes each of a, b, c to run the appropriate number of times and throw and equations into the middle to check if that combination of a,b,c works. This can be done in a single if statement using the && (and) operator.

-----------------------------------
xanderman2113
Mon Nov 10, 2014 6:10 pm

Re: RE:Any help with this grade 11 program relating to Pythagorean Triplets?
-----------------------------------
Basically you're just tossing some equations into a nested for loop. Should look something like this:



Thanks for the starting code, I think I know what I need to do now. I will get back to you. Thanks!

-----------------------------------
xanderman2113
Mon Nov 10, 2014 8:29 pm

Re: Any help with this grade 11 program relating to Pythagorean Triplets?
-----------------------------------
Alright I got this pretty much down pat just one small error I can't seem to find. Here is a direct link to the picture: http://prntscr.com/555qkd
Thanks!

-----------------------------------
Tony
Mon Nov 10, 2014 9:20 pm

RE:Any help with this grade 11 program relating to Pythagorean Triplets?
-----------------------------------
That's not a very good error message :lol: It should have told you that it has to do with = vs ==

P.S. your program's comments suggest that you are missing a part of the original requirement

whose largest member is less than or equal to that integer

