Print Triangular Array
From Java Example Source Code
Contents |
[edit] Overview - Print Triangular Array
This Java example program shows how to print a triangular [[Category:Array|array].
[edit] Java Source Code
- Package: example.array
- File: TriangularArray.java
package example.array;
public class TriangularArray {
public static void main(String[] args) {
final int MAX_HIGH = 10;
// allocate triangular arrayint[][] odds = new int[MAX_HIGH + 1][];
for (int i = 0; i <= MAX_HIGH; i++)
odds[i] = new int[i + 1];
// fill triangular arrayfor (int i = 0; i < odds.length; i++)
for (int j = 0; j < odds[i].length; j++)
odds[i][j] = i + j;
// print triangular arrayfor (int i = 0; i < odds.length; i++) {
for (int j = 0; j < odds[i].length; j++) {
System.out.print(odds[i][j] + " ");
}System.out.println();
}}}
[edit] What Result You Can Get
Run the program, you will get:
0 1 2 2 3 4 3 4 5 6 4 5 6 7 8 5 6 7 8 9 10 6 7 8 9 10 11 12 7 8 9 10 11 12 13 14 8 9 10 11 12 13 14 15 16 9 10 11 12 13 14 15 16 17 18 10 11 12 13 14 15 16 17 18 19 20
[edit] Required External Libraries and/or Files for this Java Example
Need nothing.
http://www.ase2009.com/ online casino 132 http://www.hellzyea.com/health health insurance 8DDD http://www.yourautoinsurancesite.com/ auto insurance quotes 135811 http://www.makemeasammich.com/ auto insurance mcnxu
[edit] Question & Answer
Any question?
Click edit and post your question or answer here.
