Skip to content

Instantly share code, notes, and snippets.

@adityasatrio
Created February 4, 2015 14:35
Show Gist options
  • Save adityasatrio/a972f63e3a9b13a4dd87 to your computer and use it in GitHub Desktop.
Save adityasatrio/a972f63e3a9b13a4dd87 to your computer and use it in GitHub Desktop.
equilateral triangular using loop
import java.util.ArrayList;
public class Triangular {
public static int triangular(int totalDot) {
System.out.print("\n");
for (int i = 0; i < totalDot; i++) {
for (int j = 1; j <= totalDot - i; j++) {
System.out.print("*");
}
System.out.println();
}
System.out.print("\n");
}
public static void main(String[] args) {
Loop.triangular(1);
Loop.triangular(2);
Loop.triangular(3);
Loop.triangular(4);
}
}
/**
Triangular numbers are so called because of the equilateral triangular shape that they occupy when laid out as dots. e.g.
triangle(1)
*
=> 1
triangle(2)
**
*
=> 3
triangle(3)
***
**
*
=> 6
Write a function `triangle` that prints the triangle and returns the triangular number -- number of *'s printed. It should return 0 for out of range values, but you will always be passed an integer.
*/
@adityasatrio
Copy link
Author

equilateral triangular using loop: i spent 98.58 minute for pieces of codes, shame on me, - mediocre programmer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment