From 1a278e169acb50a036e9ecb439dab5db44330a6f Mon Sep 17 00:00:00 2001 From: Ritwik Date: Fri, 2 Oct 2020 00:49:17 +0530 Subject: [PATCH 1/3] added pattern question in which we have to draw an inverted hour glass --- hacktober-1/src/invertedHourglass.java | 49 ++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 hacktober-1/src/invertedHourglass.java diff --git a/hacktober-1/src/invertedHourglass.java b/hacktober-1/src/invertedHourglass.java new file mode 100644 index 0000000..3b84f11 --- /dev/null +++ b/hacktober-1/src/invertedHourglass.java @@ -0,0 +1,49 @@ +import java.util.Scanner; + +public class invertedHourglass { + + public static void main(String[] args) { + // TODO Auto-generated method stub + Scanner scn = new Scanner(System.in); + int n = scn.nextInt(); + int nst = 1; + int nsp = 2 * n - 1; + int count = 1; + int row = 1; + while (row <= 2 * n + 1) { + count = n; + int cst = 1; + while (cst <= nst) { + System.out.print(count + " "); + cst++; + count--; + } + int csp = 1; + while (csp <= nsp) { + System.out.print(" "); + csp++; + } + cst = 1; + while (cst <= nst) { + count++; + if (cst == 1 && row == n + 1) { + count++; + cst++; + } + System.out.print(count + " "); + cst++; + } + System.out.println(); + if (row <= n) { + nst++; + nsp -= 2; + } else { + nst--; + nsp += 2; + } + row++; + + } + + } +} From 0e6d31b223f6079aab50d9880ece992a2e5f9ab9 Mon Sep 17 00:00:00 2001 From: Ritwik Date: Fri, 2 Oct 2020 00:54:15 +0530 Subject: [PATCH 2/3] Rotate an array --- hacktober-1/src/rotateAnArray.java | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 hacktober-1/src/rotateAnArray.java diff --git a/hacktober-1/src/rotateAnArray.java b/hacktober-1/src/rotateAnArray.java new file mode 100644 index 0000000..6c44ed9 --- /dev/null +++ b/hacktober-1/src/rotateAnArray.java @@ -0,0 +1,26 @@ + +public class rotateAnArray { + + public static void main(String[] args) { + // TODO Auto-generated method stub + int[] arr= {10,20,30,40}; + rotate(arr,2); + } + public static void rotate(int[] a,int n) { + + for(int i=0;i=1;j--) { + + a[j]=a[j-1];} + + a[0]=temp; + + + } + for(int val:a) { + System.out.print(val+" "); + } + + } +} From 3ddbc4524482260cc6dd330ce29c224eca0b5105 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Thu, 1 Oct 2020 19:24:47 +0000 Subject: [PATCH 3/3] Restyled by clang-format --- hacktober-1/src/invertedHourglass.java | 86 +++++++++++++------------- hacktober-1/src/rotateAnArray.java | 42 ++++++------- 2 files changed, 62 insertions(+), 66 deletions(-) diff --git a/hacktober-1/src/invertedHourglass.java b/hacktober-1/src/invertedHourglass.java index 3b84f11..bb8d140 100644 --- a/hacktober-1/src/invertedHourglass.java +++ b/hacktober-1/src/invertedHourglass.java @@ -2,48 +2,46 @@ public class invertedHourglass { - public static void main(String[] args) { - // TODO Auto-generated method stub - Scanner scn = new Scanner(System.in); - int n = scn.nextInt(); - int nst = 1; - int nsp = 2 * n - 1; - int count = 1; - int row = 1; - while (row <= 2 * n + 1) { - count = n; - int cst = 1; - while (cst <= nst) { - System.out.print(count + " "); - cst++; - count--; - } - int csp = 1; - while (csp <= nsp) { - System.out.print(" "); - csp++; - } - cst = 1; - while (cst <= nst) { - count++; - if (cst == 1 && row == n + 1) { - count++; - cst++; - } - System.out.print(count + " "); - cst++; - } - System.out.println(); - if (row <= n) { - nst++; - nsp -= 2; - } else { - nst--; - nsp += 2; - } - row++; - - } - - } + public static void main(String[] args) { + // TODO Auto-generated method stub + Scanner scn = new Scanner(System.in); + int n = scn.nextInt(); + int nst = 1; + int nsp = 2 * n - 1; + int count = 1; + int row = 1; + while (row <= 2 * n + 1) { + count = n; + int cst = 1; + while (cst <= nst) { + System.out.print(count + " "); + cst++; + count--; + } + int csp = 1; + while (csp <= nsp) { + System.out.print(" "); + csp++; + } + cst = 1; + while (cst <= nst) { + count++; + if (cst == 1 && row == n + 1) { + count++; + cst++; + } + System.out.print(count + " "); + cst++; + } + System.out.println(); + if (row <= n) { + nst++; + nsp -= 2; + } else { + nst--; + nsp += 2; + } + row++; + } + } } diff --git a/hacktober-1/src/rotateAnArray.java b/hacktober-1/src/rotateAnArray.java index 6c44ed9..b3a165e 100644 --- a/hacktober-1/src/rotateAnArray.java +++ b/hacktober-1/src/rotateAnArray.java @@ -1,26 +1,24 @@ public class rotateAnArray { - public static void main(String[] args) { - // TODO Auto-generated method stub - int[] arr= {10,20,30,40}; - rotate(arr,2); - } - public static void rotate(int[] a,int n) { - - for(int i=0;i=1;j--) { - - a[j]=a[j-1];} - - a[0]=temp; - - - } - for(int val:a) { - System.out.print(val+" "); - } - - } + public static void main(String[] args) { + // TODO Auto-generated method stub + int[] arr = {10, 20, 30, 40}; + rotate(arr, 2); + } + public static void rotate(int[] a, int n) { + + for (int i = 0; i < n; i++) { + int temp = a[a.length - 1]; + for (int j = a.length - 1; j >= 1; j--) { + + a[j] = a[j - 1]; + } + + a[0] = temp; + } + for (int val : a) { + System.out.print(val + " "); + } + } }