Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Any help with this grade 11 program relating to Pythagorean Triplets?
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
xanderman2113




PostPosted: Mon Nov 10, 2014 12:17 pm   Post subject: 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.
Sponsor
Sponsor
Sponsor
sponsor
williamd




PostPosted: Mon Nov 10, 2014 12:47 pm   Post subject: RE:Any help with this grade 11 program relating to Pythagorean Triplets?

yes
Insectoid




PostPosted: Mon Nov 10, 2014 12:54 pm   Post subject: 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
        }
    }
}


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




PostPosted: Mon Nov 10, 2014 6:10 pm   Post subject: Re: RE:Any help with this grade 11 program relating to Pythagorean Triplets?

Insectoid @ Mon Nov 10, 2014 12:54 pm wrote:
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
        }
    }
}


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.


Thanks for the starting code, I think I know what I need to do now. I will get back to you. Thanks!
xanderman2113




PostPosted: Mon Nov 10, 2014 8:29 pm   Post subject: 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




PostPosted: Mon Nov 10, 2014 9:20 pm   Post subject: RE:Any help with this grade 11 program relating to Pythagorean Triplets?

That's not a very good error message Laughing 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
Quote:

whose largest member is less than or equal to that integer
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 6 Posts ]
Jump to:   


Style:  
Search: