You didn't really explain the specifics of the triangle, so this first example here is a left aligned triangle. I formatted it my way since you didn't properly format the post - please use
code tags when posting code. There's many ways to do it... and I fancy for loops in case you didn't notice.
Replace your two while loops with either of the below snippets of code:
...
for (i = 0; i < stars; i++) {
for (j = 0; j <= i; j++) {
System.out.print("*");
}
System.out.println();
}
...
Since your square was hollow, here's a hollow triangle - also left aligned:
...
for (i = 0; i <= stars; i++) {
for (j = 0; j <= i; j++) {
if (i == stars) {
for (int x = 0; x<= stars; x++)
System.out.print("*");
break;
} else if (i > 1) {
System.out.print("*");
for (int k = 0; k < i - 1; k++)
System.out.print(" ");
System.out.print("*");
break;
} else
System.out.print("*");
}
System.out.println();
}
...