Skip to content

added pattern question in which we have to draw an inverted hour glass #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
49 changes: 49 additions & 0 deletions hacktober-1/src/invertedHourglass.java
Original file line number Diff line number Diff line change
@@ -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++;

}

}
}
26 changes: 26 additions & 0 deletions hacktober-1/src/rotateAnArray.java
Original file line number Diff line number Diff line change
@@ -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<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+" ");
}

}
}