Hello guys,
I'm really stumped on this assignment. What I need to do is make a triangle's height based on the number entered by the user. So if the user enteres 4, the output would be this:
$
$$
$$$
$$$$
And I can't figure out how to do that. What I have so far will print '$' down the screen. If I enter '4', it will print '$' down the screen 25 times, and of course, I know that's not right.
// Name: John Mollman
// Class: Java 1 - 5271
// Abstract: CHomework4A
// Imports -------------
import java.util.Scanner;
public class CHomework4A
{
public static void main(String[] astrCommandLine)
{
// Get data from the user and store it in the variable 'intTriangleHeight'
Scanner inputDevice = new Scanner(System.in);
int intTriangleHeight = 0;
// Loop until the user enters a number within 1 and 20
do
{
System.out.println("Height of the triangle?");
intTriangleHeight = inputDevice.nextInt();
} while ((intTriangleHeight < 1) || (intTriangleHeight > 20));
// Set a number of lines based on the height of the trianle
// entered above
for (int intIndex1 = 0; intIndex1 <= intTriangleHeight; intIndex1 += 1)
{
String strOutputLine = "$"; // Defines '$' as a building block
// Print the number of '$' signs to go across
for (int intIndex2 = 0; intIndex2 <= intTriangleHeight; intIndex2 += 1)
{
System.out.println(strOutputLine);
}
}
}
}