Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions hacktober-1/src/invertedHourglass.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
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++;
}
}
}
24 changes: 24 additions & 0 deletions hacktober-1/src/rotateAnArray.java
Original file line number Diff line number Diff line change
@@ -0,0 +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 < 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 + " ");
}
}
}