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++; + + } + + } +} 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+" "); + } + + } +}