the results i need are like this...
user input...4
*
**
***
****
***
**
*
This code does half of the needed result.
any help would be great, thanks in advance.
import java.util.*;
public class Triangle
{
public static void main(String[]args)
{
int n = 0;
int spaces = n;
int ast;
System.out.println("Please enter a number and i will draw a triangle with these *");
Scanner keyboard = new Scanner(System.in);
n = keyboard.nextInt();
for(int i = 0; i < n; i++)
{
ast = 2*i+1;
for(int j = 1; j <= spaces+ast; j++)
{
if(j <= spaces)
System.out.print(' ');
else
System.out.print('*');
}
System.out.println();
spaces--;
}
}
}

New Topic/Question
Reply




MultiQuote






|