# Thread: Help Numeric Triangle java

1. Member
Join Date
Sep 2013
Posts
15
Rep Power
0

## Help Numeric Triangle java

So I have to make a triangle figure just like you see below and I can't get it right, first of all the user has to enter "3" in order to print the triangle and I'm having problems with math, so I get 1 and 2 and 3 but I cant find where exactly decree (--) to go from 2 to 0 and then back to 2 and so on.

Java Code:
```import java.io.BufferedReader;
import java.io.IOException;

/*       1
*
*    2  0  2
*
*  3 0  0  0  3
*
*/

public class Triangle {

public static void main(String[] args) throws NumberFormatException, IOException {
System.out.println ("Enter number 3");

int numOfColumns=1;
int start=0;
int numOfSpaces=number/2;
for( int i=1; i<=number; i++)
{
if (i<number/2+1)
{
start=i;
}
else
{
start=(number+1)-i;
numOfSpaces=numOfSpaces+1;
}
for (int j=1; j<=numOfSpaces; j++)
{
System.out.print(" ");
}
numOfSpaces=numOfSpaces-1;
for (int j=1; j<=numOfColumns; j++)
{
int middleColumn=numOfColumns/2+1;
System.out.print(start);
if (j<middleColumn)
{
start--;

}
else
{
start++;
}
}
System.out.println ();
if (i<number/2)
{
numOfColumns = numOfColumns+2;
}
else
{
numOfColumns = numOfColumns-2;
break;
}
}
}

}```

2. ## Re: Help Numeric Triangle java

Think about the algorithm. On each line you have s number of spaces followed by a number n. For each subsequent line the number of spaces decreases and the number increases. Take it a step at a time, try getting the following to output before going any further:
Java Code:
```        1
2
3```

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•