تفضلي
اهم شي تكوني فاهم الكود لو طلبت تشرحي لها .. اوكي
كود PHP:
Scanner keyboard = new Scanner (System.in);
int input, i, j;
System.out.println("Enter the size you want your triangle to be:[from 1 to 50]?");
input = keyboard.nextInt();
//i is the amount of line that will run until its = tri. it increments everytime it runs the loop
if(input>=1 &&input<=50){
for (i = 1; i <= input; i++)
{
//prints asterisks j times. j has to print out by the amount of lines (line 2 = 2 asterisks)
//so make it <= to i and increment
for (j = 1; j <= i; j++)
{
System.out.print("*");
}
System.out.println();
}
//same thing, reversed
for (i = input - 1; i >= 0; i--)
{
for (j = 1; j <= i; j++)
{
System.out.print("*");
}
System.out.println();
}
}
else{
System.out.println("Please enter the numbers only between 1 to 50");
}