...

/

Examples of Algorithms: Part 3

Examples of Algorithms: Part 3

We'll look at different algorithms that help in solving problems.

Coding example: 75

We might use the loop statement to form many types of patterns. The triangle pattern is one of them. Let’s take a look at its example first.

Press + to interact
// how to create triangle patterns
class TrianglePattern{
public void printStars(int n){
int i, j;
for(i=0; i < n; i++)
{
for(j=0; j<=i; j++)
{
System.out.print("* ");
}
System.out.println();
}
}
}
public class ExampleSeventyFive
{
static int num = 0;
public static void main(String args[])
{
TrianglePattern patternObject = new TrianglePattern();
num = 5;
patternObject.printStars(num);
}
}

Coding example: 76

This example seems to ...

Access this course and 1400+ top-rated courses and projects.