I tested the program out with 88 and it was left with one star to complete the triangle. 87, two stars 86 three stars. This went on for certain numbers.
import java.util.*;
public class TriangleSingle
{
public static void generate(int x) //Generates the Triangle
{
int len, count;
len = 1;
count = 1;
for (int k = 1; k <= x; k++)
{
System.out.print("*");
count --;
if (count == 0)
{
System.out.println();
len ++;
count = len;
}
}
if (count!= 0 || count != len)
{
System.out.println("*"); //Completes the triangle if needed
// This is the **problem spot**
}

Aucun commentaire:
Enregistrer un commentaire