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