Thread: Making triangle
View Single Post
  #2 (permalink)  
Old 01-30-2008, 09:49 AM
tim's Avatar
tim tim is offline
Senior Member
 
Join Date: Dec 2007
Location: South Africa
Posts: 334
tim is on a distinguished road
Okay
Hello banie

I indented and tested your code and it looks file:
Code:
public class Banie { private final int height; private final int width; public Banie(final int height, final int width) { // Constructor this.height = height; this.width = width; } public void print() { for (int line = 0; line < height; line++) { final double percentage = line / (double) height; final int item = (int) (percentage * width) + 1; // Type casting for (int at = 0; at < item; at++) { System.out.print("@"); } System.out.println(); if ( height == item); } } }
It gives output
Code:
@ @@ @@@ @@@@ @@@@@ @@@@@@ @@@@@@@
Is this what you wanted? Or, do you need:
Code:
@ @@@ @@@@@ @@@@@@@
__________________
If your ship has not come in yet then build a lighthouse.

Last edited by tim : 01-30-2008 at 09:57 AM.
Reply With Quote