Hi everyone,
I'm assigned to make a triangle using numbers and I'm only allowed to use while loop
the program should give output like this
*****1
****121
***12221
**1222221
*122222221
(Ignore the "asterisks,*")
I've sorted out how to make a triangle but I can't figure out how to display the above written output.
this is the code
class numtriangle{
public static void main(String a[]){
int trianglesize =10;
int num = 1;
int spaces = trianglesize / 2;
int count = 0;
while (num <= trianglesize)
{
while (count < spaces)
{
System.out.print(" ");
count++;
}
count = 0;
while (count < num)
{
System.out.print("1");
count++;
}
count = 0;
spaces--;
num++;
num++;
System.out.println();
}
}
}
and this generates the below output
*****1
****111
***11111
**1111111
*111111111
any of you guys might want to help would be highly appreciated