|
-
Jan 4th, 2007, 06:39 PM
#1
Thread Starter
New Member
IsoTriangle help
i have created a program which prompts the user for the size of an isoceles triangle and then displas the triangle with that many lines but according to myy project it alsso have to inclue drawBar() method and Addspace method which prints the space how can i do that
int size;
System.out.print("Enter Size: ");
size = input.nextInt();
int temp = size;
for (int i = 1; i <= size; i++){
for (int j = temp; j > 0; j--){
System.out.print(" ");
}
for(int j = 0; j < i; j++){
System.out.print("*");
System.out.print(" ");
}
System.out.println();
temp--;
}
-
Jan 5th, 2007, 04:13 PM
#2
Frenzied Member
Re: IsoTriangle help
post your attempt at drawBar() addSpace() and I will help.
-
Jan 5th, 2007, 05:38 PM
#3
Thread Starter
New Member
Re: IsoTriangle help
int size;
System.out.print("Enter Size: ");
size = input.nextInt();
int temp = size;
drawBar(temp, size);
}
public static void drawBar(int temp, int size) {
for (int i = 1; i <= size; i++){
for(int j = 0; j < i; j++){
System.out.print("*");
System.out.print(" ");
}
System.out.println();
temp--;
}
}
public static void addSpaces (int temp, int size){
for (int i = 1; i <= size; i++){
for (int j = temp; j > 0; j--){
System.out.print(" ");
}
}
}
-
Jan 6th, 2007, 01:36 PM
#4
Addicted Member
Re: IsoTriangle help
does the apex of your triangle point up or down?
-
Jan 7th, 2007, 04:22 PM
#5
Thread Starter
New Member
-
Jan 8th, 2007, 02:01 AM
#6
Addicted Member
Re: IsoTriangle help
I had almost the exact same question on my midterm, the only difference was that we had to make a diamond so we had to make the isometric triangle and then just flip it over again.... I will give you this for now, try out some of your code and then we can help you fix it up more
I found it best to draw out the asterixs and then look for patterns,
some key forumulas that I found out (if you havn't found them out already)
1) the triangle is bounded by a (2*n - 1) by (2*n - 1) square, so that means the last row has (2*n - 1) asterixs
2) the number of asterixs start at one and increase by two every row, so the number in any row is (2 * row - 1) [this is almost the same idea as the one above]
3) the number of spaces before and after the asterixs is the same. You only have to output the ones infront. The number of spaces before the asterixs for any row can be obtained by (totalRows - currentRow)
Hope this helps
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|