?
Solved

Pythagorean Triples - 2nd intro. class to Java programming

Posted on 2000-04-21
3
Medium Priority
?
1,812 Views
Last Modified: 2008-03-06
5.18 (Pythagorean Triples) A right triangle can have sides that are all integers.  The set of three integer values for the sides of a right triangle is called a Pythagorean triple.  These three sides must satisfy the relationship that the sum of the squares of two of the sides is equal to the square of the hypotenuse.  Find all Pythagorean triples for side l, side2, and the hypotenuse all no larger than 500.  Use a triple-nested for-loop that tries all possibilities.  This is an example of "brute force" computing.  You will learn in more advanced computer science courses that there are large numbers of interesting problems for which there is no known algorithmic approach other than using sheer brute force.

Write the Java application of exercise 5.18 with the following modifications:
Name the source file Project2.java.
Let the range of side sizes be variable, instead of the fixed 1 to 500 specified in the text.
Allow the user to input the smallest size, but insure this size is at least 1 and at most 500 before allowing execution to continue. In other words, if the user enters 0 or 501, the program should request another value before going on to the next step (and this repetition should continue until an appropriate value is entered).
Allow the user to input the largest size, but insure this size is at least the smallest size and at most 500.
Print all of the Pythagorean triples, with sides at least the smallest and at most the largest size, one per line with appropriate labels. For example, here is adequate output for smallest=5 and largest=15 (a and b are the two sides adjacent the right angle, and h is the hypotenuse):
a: 5, b: 12, h: 13
a: 6, b: 8, h: 10
a: 8, b: 6, h: 10
a: 9, b: 12, h: 15
a: 12, b: 5, h: 13
a: 12, b: 9, h: 15


I need halp on this question...I am in a Java programming class  can someone please help me????  Thanks
0
Comment
Question by:volcomman9
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 

Expert Comment

by:scooter1
ID: 2739265
might want to post this in the java topic area
0
 
LVL 1

Expert Comment

by:darkskyz
ID: 2739661
this isn't the place to get your homework done for you.
0
 

Accepted Solution

by:
ecaterina9 earned 300 total points
ID: 2781983
//range of side sizes be variable,
int smallest;
int largest;
//do the input box + validation  
//look in "Java How to Program" by //Deitel& Deitel for patterns for this
//Use a triple-nested for-loop that //tries all possibilities
for(int k=smallest;k=largest;k++)
for(int p=smallest;p=largest;p++)
for(for q=smallest;q=largest;q++)
if(k*k+p*p==q*q)
cout<<k<<p<<q;//use a Java GUI call here

0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question