Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Solved

Posted on 2010-09-19

//Newtocoding

//Java program for pythagorean triple for loop

/*5.21 (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

*/

//Newtocoding

//Java program for pythagorean triple for loop

I need to use 3 for loops and prompt for input and display

import java.util.Scanner;

public class PythagoreanTripleForLoop

{

public static void main(String[] args)

{

Scanner number = new Scanner(System.in);

System.out.print("Enter length of side A of triangle's sides from 1 to 1000: ");

sideA = number.nextInt();

System.out.print("Enter length of side B of triangle's sides from 1 to 1000: ");

sideB = number.nextInt();

System.out.print("Enter length of side H of triangle's sides from 1 to 1000: ");

sideH = number.nextInt();

int sideA=0;

int sideB=0;

int sideH=0;

static int max = 1000;

if (sideA>max; sideB>max;sideH>max) {

System.out.println("You entered an invalid number");

}

else {

for(sideA=1;sideA<=max;sideA++)

for(sideB=1;sideB<=max;sideB++)

for(sideH=1;sideH<=max;sideH++)

if(a*a+b*b==c*c)

System.out.printf(String formatString="%"+widthOfBiggestNumber+"d" a,b,c)

formatString=formatString+"%"+widthOfNextColumn+"d";

else

System.out.print("Not a pythagorean triangle")

biggestNumber=0;

String biggestNumber=""+ biggestNumber;

biggestNumberString=biggestNumberString.length();

//Java program for pythagorean triple for loop

/*5.21 (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

*/

//Newtocoding

//Java program for pythagorean triple for loop

I need to use 3 for loops and prompt for input and display

import java.util.Scanner;

public class PythagoreanTripleForLoop

{

public static void main(String[] args)

{

Scanner number = new Scanner(System.in);

System.out.print("Enter length of side A of triangle's sides from 1 to 1000: ");

sideA = number.nextInt();

System.out.print("Enter length of side B of triangle's sides from 1 to 1000: ");

sideB = number.nextInt();

System.out.print("Enter length of side H of triangle's sides from 1 to 1000: ");

sideH = number.nextInt();

int sideA=0;

int sideB=0;

int sideH=0;

static int max = 1000;

if (sideA>max; sideB>max;sideH>max) {

System.out.println("You entered an invalid number");

}

else {

for(sideA=1;sideA<=max;sid

for(sideB=1;sideB<=max;sid

for(sideH=1;sideH<=max;sid

if(a*a+b*b==c*c)

System.out.printf(String formatString="%"+widthOfBi

formatString=formatString+

else

System.out.print("Not a pythagorean triangle")

biggestNumber=0;

String biggestNumber=""+ biggestNumber;

biggestNumberString=bigges

Question has a verified solution.

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

Title | # Comments | Views | Activity |
---|---|---|---|

NetBeans and configurationfiles | 2 | 51 | |

Aptana 3.6 Preview Problem On Mac | 35 | 124 | |

How to jump to matching brace in eclipse editor ? | 1 | 293 | |

regex. How to include lines between | 10 | 83 |

The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

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