diff --git a/Practice Problems/Patterns/Sandglass/README.md b/Practice Problems/Patterns/Sandglass/README.md new file mode 100644 index 0000000..23f57f2 --- /dev/null +++ b/Practice Problems/Patterns/Sandglass/README.md @@ -0,0 +1,24 @@ +# Sandglass + +Given a side `n` print a pattern of Sandglass. + +### Example: +**Input** : `6` + +**Output:** : + +``` +* * * * * * + * * * * * + * * * * + * * * + * * + * + * + * * + * * * + * * * * + * * * * * +* * * * * * +``` + diff --git a/Practice Problems/Patterns/Sandglass/Sandglass.java b/Practice Problems/Patterns/Sandglass/Sandglass.java new file mode 100644 index 0000000..9318b55 --- /dev/null +++ b/Practice Problems/Patterns/Sandglass/Sandglass.java @@ -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 = 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(); + } +} \ No newline at end of file