fork(1) download
  1. /*
  2. Given a number N, the program must print the pattern as described below.
  3.  
  4. Input Format:The first line contains the value of the N which represent the number N.
  5. Boundary Conditions:2 <= N <= 9
  6. Output Format:The pattern as described below in the Example
  7.  
  8. Input:
  9. 4
  10.  
  11. Output:
  12. 4444444
  13. 4333334
  14. 4322234
  15. 4321234
  16. 4322234
  17. 4333334
  18. 4444444
  19.  
  20. */
  21.  
  22. import java.util.Scanner;
  23.  
  24. class Ideone {
  25. public static void main(String[] args) {
  26. Scanner sc = new Scanner(System.in);
  27. int N = sc.nextInt();
  28. for(int i = N; i>(1); i--) //Print upper part
  29. {
  30. for(int j = N; j >i; j--)
  31. System.out.print(j);
  32. for(int j = 0; j<(i*2)-1; j++)
  33. System.out.print(i);
  34. for(int j = i+1; j<=N; j++)
  35. System.out.print(j);
  36. System.out.println("");
  37. }
  38. for(int i = 1; i<=(N); i++)// print lower part
  39. {
  40. for(int j = N; j>i; j--)
  41. System.out.print(j);
  42. for(int j = 0; j<(i*2)-1; j++)
  43. System.out.print(i);
  44. for(int j = i+1; j <=N; j++)
  45. System.out.print(j);
  46. System.out.println("");
  47. }
  48. }
  49. }
  50.  
Success #stdin #stdout 0.14s 321344KB
stdin
4
stdout
4444444
4333334
4322234
4321234
4322234
4333334
4444444