some code samples, various examples of simple modeling ideas and some minor algorithms.

TriangleTwo.java 667B

123456789101112131415161718192021222324252627282930
  1. class TriangleTwo {
  2. // Print a horizontal row of XTRIANGLES bottom-left right-angled triangles
  3. // of stars, each of size SIZE
  4. static final int SIZE=6;
  5. static final int XTRIANGLES=9;
  6. public void display()
  7. {
  8. this.display(XTRIANGLES, SIZE);
  9. }
  10. public void display(int num, int size)
  11. {
  12. for(int i=0;i<size;i++)
  13. {
  14. for(int k=0;k<num;k++)
  15. {
  16. int j;
  17. for(j=0;j<=i;j++)
  18. System.out.print("*");
  19. for(;j<size;j++)
  20. System.out.print(" ");
  21. }
  22. System.out.println();
  23. }
  24. }
  25. }