JAVA TUTORIALS
▼
ENVIRONMENT SETUP
▼
DECLARATION AND ASSIGNMENTS
▼
FLOW CONTROL
▼
MISCELLANEOUS
▼
JAVA OOPS
▼
OTHERS
▼
Interview Questions
▼
Java Program for Reverse Floyd Triangle - Half Floyd number diamond ~ foundjava
package demo;public class FloydTriangle{
public static void main(String[] args) { int num = 4, y; y = num + 1; for (int r = 1; r <= num; r++, y--) { for (int c = 1, n = num; c <= r; c++, n--) { System.out.print(" " + n); } for (int c = 1, p = y; c < r; c++, p++) { System.out.print(" " + p); } System.out.println(); } for (int r = num - 1, x = 1; r >= 1; r--, x--) { for (int c = r, n = num; c >= 1; c--, n--) { System.out.print(" " + n); } for (int c = r, z = num - x; c > 1; c--, z++) { System.out.print(" " + z); } System.out.println(); } }}
Output:
4 4 3 4 4 3 2 3 4 4 3 2 1 2 3 4 4 3 2 3 4 4 3 4 4
BUILD SUCCESSFUL (total time: 1 second)
No comments:
Post a Comment