Java Tutorial, Java Study, Learn Java, Java Lab@home, Java Cycle test, Java Projects, Java Assignments, Java Notes and much more..
JAVA TUTORIALS
▼
ENVIRONMENT SETUP
▼
DECLARATION AND ASSIGNMENTS
▼
FLOW CONTROL
▼
MISCELLANEOUS
▼
JAVA OOPS
▼
OTHERS
▼
Interview Questions
▼
Sunday, 25 June 2017
Java Program for Number Pattern of Half Diamond ~ foundjava
package demo; import java.util.Scanner; public classHalfDaimond { public static voidmain(String[] args) { int num, q; Scanner sc = new Scanner(System.in); System.out.print("Enter Seeding Number : "); num = sc.nextInt(); for (int r = 1, n = num; r <= num; r++, n--) { for (int c = r, p = n; c >= 1; c--, p++) { System.out.print(p); } for (int c = r, p = num - 1; c > 1; c--, p--) { System.out.print(p); } System.out.println(); } for (int r = 1; r < num; r++) { for (int c = r, p = r + 1; c < num; c++, p++) { System.out.print(p); } for (int c = num - r, p = num - 1; c > 1; c--, p--) { System.out.print(p); } System.out.println(); } } } Output: Enter Seeding Number : 4 4 343 23432 1234321 23432 343 4
No comments:
Post a Comment