• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Could someone tell me what it is that I am leaving out in order to obtain output...

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No doubt this problem is simple for most; however, I seem to be having difficulty in producing any output. It compiles...just doesn't output anything. Where have I gone wrong, may I ask? Thanks in advance!


public class PythagoreanTriples
{

public static void main( String args[] )
{
int side1;
int side2;
int hypotenuse;
int limit = 5;
int i=0;

/* Loop for side1 to try the values 1-limit. */
for (side1=1; side1<limit; ++side1)
{

/* Loop for side2 to try the values 1-limit. */
for (side2=side1+1; side2<limit; ++side2)
{side2+= side2;

/* Loop for hypotenuse to try the values 1-limit */
for(hypotenuse=side2+1; hypotenuse<limit; ++hypotenuse)
{

/* An if statement that determines whether the sum of the two sides squared equals the hypotenuse squared. If this condition is true display side1, side2 and hypotenuse. */
if(side1*side1+side2*side2 == hypotenuse*hypotenuse)
{
System.out.printf(" %d : ( %d, %d, %d )\n", ++i, side1, side2, hypotenuse);
} // end if
} //end innermost for
} //end inner for
} //end outer for
} //end main

} // end class Triples
 
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
System.out.printf ??

Try:
System.out.print() OR
System.out.println()
[ July 20, 2005: Message edited by: Scheepers de Bruin ]
 
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Adding println's inside each loop shows that it never enters your 'innermost' for loop, hence no output.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!