Results 1 to 5 of 5
Thread: Making triangle
- 01-30-2008, 08:07 AM #1
Member
- Join Date
- Jan 2008
- Posts
- 21
- Rep Power
- 0
Making triangle
Hi,
I just wanna do triangle. The output is like this:
@
@@
@@@
@@@@
@@@@@
@@@@@@
@@@@@@@
@@@@@@@
Here is my code:
Java 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); } } public static void main(String[] args) { Banie t = new Banie(7, 7); // Parsing args t.print(); // Calling method } }
- 01-30-2008, 08:49 AM #2
Okay
Hello banie :D
I indented and tested your code and it looks file:
It gives outputJava 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); } } }
Is this what you wanted? Or, do you need:Java Code:@ @@ @@@ @@@@ @@@@@ @@@@@@ @@@@@@@
Java Code:@ @@@ @@@@@ @@@@@@@
Last edited by tim; 01-30-2008 at 08:57 AM.
Eyes dwelling into the past are blind to what lies in the future. Step carefully.
- 02-02-2008, 08:27 AM #3
banie, this topic was discussed recently... you may wish to use the search feature next time. When you use the search, compare your code to the code you find from others. This helps to strengthen your coding "eyes" and reasoning ability/logic skills.
Vote for the new slogan to our beloved Java Forums! (closes on September 4, 2008)
Want to voice your opinion on your IDE/Editor of choice? Vote now!
Got a little Capt'n in you? (drink responsibly)
- 02-02-2008, 11:07 AM #4
Member
- Join Date
- Jan 2008
- Posts
- 21
- Rep Power
- 0
The output that i want is like this:
@
@@
@@@
@@@@
@@@@@
@@@@@@
@@@@@@@
@@@@@@@
- 02-02-2008, 11:23 AM #5
Vote for the new slogan to our beloved Java Forums! (closes on September 4, 2008)
Want to voice your opinion on your IDE/Editor of choice? Vote now!
Got a little Capt'n in you? (drink responsibly)
Similar Threads
-
change the square to triangle java
By anotsu in forum New To JavaReplies: 3Last Post: 07-09-2009, 11:17 AM -
Triangle
By jkswebsite in forum New To JavaReplies: 8Last Post: 01-10-2009, 02:08 PM -
Computing the area of a triangle using Heron's Formula
By Java Tip in forum java.langReplies: 0Last Post: 04-12-2008, 08:39 PM -
Help with making this algorithm better
By RLRExtra in forum New To JavaReplies: 6Last Post: 01-17-2008, 04:11 PM -
Making a session in swing
By sandor in forum AWT / SwingReplies: 3Last Post: 04-22-2007, 10:58 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks