Skip to content

#62 Sandglass Pattern Java Practice Problem #69

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

Merged
merged 3 commits into from
Oct 3, 2020
Merged
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
24 changes: 24 additions & 0 deletions Practice Problems/Patterns/Sandglass/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Sandglass

Given a side `n` print a pattern of Sandglass.

### Example:
**Input** : `6`

**Output:** :

```
* * * * * *
* * * * *
* * * *
* * *
* *
*
*
* *
* * *
* * * *
* * * * *
* * * * * *
```

42 changes: 42 additions & 0 deletions Practice Problems/Patterns/Sandglass/Sandglass.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import java.util.*;
import java.io.*;

public class Sandglass
{
public static void main(String[] args)
{
System.out.println("Enter number of rows you want to print: ");

Scanner input = new Scanner(System.in);
int numRow = input.nextInt();

for (int i= 0; i<= numRow-1 ; i++)
{
for (int j=0; j <i; j++)
{
System.out.print(" ");
}

for (int k=i; k<=numRow-1; k++)
{
System.out.print("* ");

}

System.out.println("");
}
for (int i= numRow-1; i>= 0; i--)
{
for (int j=0; j< i ;j++)
{
System.out.print(" ");
}
for (int k=i; k<=numRow-1; k++)
{
System.out.print("* ");
}
System.out.println("");
}
input.close();
}
}