Write a java program. User enters size of a triangle from 1-50. Print the triangle in asterisks. The user's input is the middle of the triangle. For example, if the input is 3, the triangle will look like this:
*
**
***
**
*
You have to use nested for loops. So far i did the top half of the triangle:
for(row = 1; row <= size; row++)
{
for(col = 1 ; col <= row ; col++)
{
System.out.print("*");
}
System.out.println();
}
Now i have to do the bottom half and do not know how.
1
Expert's answer
2010-10-28T12:41:22-0400
int size = 50;
for(int row = 1; row <= 2*size - 1; row++) { int cnt = row; if (row > size) cnt = 2*size - row; for(int col = 1 ; col <= cnt; ++col) { System.out.print("*");
Numbers and figures are an essential part of our world, necessary for almost everything we do every day. As important…
APPROVED BY CLIENTS
"assignmentexpert.com" is professional group of people in Math subjects! They did assignments in very high level of mathematical modelling in the best quality. Thanks a lot
Comments
Leave a comment