Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
01a7efc
commit 98b7853
Showing
20 changed files
with
1,530 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import java.util.Scanner; | ||
|
||
/*** | ||
* Pattern #1 | ||
* input = 5 | ||
* 1 | ||
* 1 2 | ||
* 1 2 3 | ||
* 1 2 3 4 | ||
* 1 2 3 4 5 | ||
*/ | ||
|
||
public class Pattern1 { | ||
public static void main (String[] args) { | ||
System.out.println("/* ===== Pattern #1 ===== */"); | ||
Scanner input = new Scanner (System.in); | ||
int n = input.nextInt(), i, j; | ||
|
||
// Print the pattern | ||
for (i=1; i<=n; i++) { | ||
for (j=1; j<=i; j++) { | ||
System.out.print(j + " "); | ||
} | ||
System.out.println(""); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* @author MadhavBahlMD | ||
* @date 26/12/2018 | ||
*/ | ||
|
||
import java.util.Scanner; | ||
|
||
/** | ||
* Pattern #2 (Floyds Triangle) | ||
* input = 4 | ||
* 1 | ||
* 2 3 | ||
* 4 5 6 | ||
* 7 8 9 10 | ||
*/ | ||
|
||
public class Pattern2 { | ||
public static void main (String[] args) { | ||
System.out.println("/* ===== Pattern #2 ===== */"); | ||
Scanner input = new Scanner(System.in); | ||
int n = input.nextInt(), i, j, count=0; | ||
|
||
// Print the pattern | ||
for (i=1; i<= n; i++) { | ||
for (j=1; j<=i; j++) { | ||
count++; | ||
System.out.print(count + " "); | ||
} | ||
System.out.println(""); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/** | ||
* @author MadhavBahlMD | ||
* @date 26/12/2018 | ||
*/ | ||
|
||
/** | ||
* Pattern #3 | ||
* input = 4 | ||
* 1 | ||
* 1 2 | ||
* 1 2 3 | ||
* 1 2 3 4 | ||
* 1 2 3 | ||
* 1 2 | ||
* 1 | ||
*/ | ||
|
||
import java.util.Scanner; | ||
|
||
public class Pattern3 { | ||
public static void main (String[] args) { | ||
System.out.println("/* ===== Pattern #3 ===== */"); | ||
Scanner input = new Scanner(System.in); | ||
int n = input.nextInt(), i, j; | ||
|
||
// Print the upper half | ||
for (i=1; i<=n; i++) { | ||
for (j=1; j<=i; j++) { | ||
System.out.print(j + " "); | ||
} | ||
System.out.println(""); | ||
} | ||
|
||
// Print the lower half | ||
for (i=n-1; i>=1; i--) { | ||
for (j=1; j<=i; j++) { | ||
System.out.print(j + " "); | ||
} | ||
System.out.println(""); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/** | ||
* @author MadhavBahlMD | ||
* @date 26/12/2018 | ||
*/ | ||
|
||
/** | ||
* 1 | ||
* 2 3 2 | ||
* 3 4 5 4 3 | ||
* 4 5 6 7 6 5 4 | ||
* 5 6 7 8 9 8 7 6 5 | ||
*/ | ||
|
||
import java.util.Scanner; | ||
|
||
public class Pattern4 { | ||
public static void main (String[] args) { | ||
System.out.println("/* ===== Pattern #4 ===== */"); | ||
Scanner input = new Scanner(System.in); | ||
int n = input.nextInt(), i, j; | ||
|
||
for (i=1; i<=n; i++) { | ||
// Print left white spaces | ||
for (j=n; j>i; j--) { | ||
System.out.print(" "); | ||
} | ||
|
||
// Print the numbers | ||
for (j=i; j<=(2*i-1); j++) { | ||
System.out.print(j + " "); | ||
} | ||
|
||
for (j=(2*i-1) - 1; j>=i; j--) { | ||
System.out.print(j + " "); | ||
} | ||
|
||
System.out.println(""); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/** | ||
* @author MadhavBahlMD | ||
* @date 26/12/2018 | ||
*/ | ||
|
||
/** | ||
* input = 5 | ||
* | ||
* * * * * * * * * * | ||
* * * * * * * * | ||
* * * * * * | ||
* * * * | ||
* * | ||
*/ | ||
|
||
import java.util.Scanner; | ||
|
||
public class Pattern5 { | ||
public static void main (String[] args) { | ||
System.out.println("/* ===== Pattern #5 ===== */"); | ||
Scanner input = new Scanner(System.in); | ||
int n = input.nextInt(), i, j; | ||
|
||
// Print the pattern | ||
for (i=1; i<=n; i++) { | ||
// Print whitet spaces | ||
for (j = 1; j < i; j++) { | ||
System.out.print(" "); | ||
} | ||
|
||
// Print asterisk | ||
for (j = 1; j <= (2 * n - (2 * i - 1)); j++) { | ||
System.out.print("* "); | ||
} | ||
System.out.println(""); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/** | ||
* @author MadhavBahlMD | ||
* @date 26/12/2018 | ||
*/ | ||
|
||
/** | ||
* input = 4 | ||
* * | ||
* * * * | ||
* * * * * * | ||
* * * * * * * * | ||
* * * * * * | ||
* * * * | ||
* * | ||
*/ | ||
|
||
import java.util.Scanner; | ||
|
||
public class Pattern6 { | ||
public static void main (String[] args) { | ||
System.out.println("/* ===== Pattern #6 ===== */"); | ||
Scanner input = new Scanner(System.in); | ||
int n = input.nextInt(), i, j; | ||
|
||
// Print upper pyramid | ||
for (i=1; i<=n; i++) { | ||
// Print white spaces | ||
for (j=1; j<=n-i; j++) { | ||
System.out.print(" "); | ||
} | ||
|
||
// Print asterisks | ||
for (j=1; j<=(2*i - 1); j++) { | ||
System.out.print("* "); | ||
} | ||
|
||
System.out.println(""); | ||
} | ||
|
||
// Print lower pyramid | ||
for (i=n-1; i>=1; i--) { | ||
// Print white spaces | ||
for (j=1; j<=n-i; j++) { | ||
System.out.print(" "); | ||
} | ||
|
||
// Print asterisks | ||
for (j=1; j<=(2*i - 1); j++) { | ||
System.out.print("* "); | ||
} | ||
|
||
System.out.println(""); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/** | ||
* @author MadhavBahlMD | ||
* @date 26/12/2018 | ||
*/ | ||
|
||
/** | ||
* input = 4 | ||
* | ||
* * * * * * * * * * | ||
* * * * * * * | ||
* * * * * | ||
* * * | ||
* * * * * | ||
* * * * * * * | ||
* * * * * * * * * * | ||
*/ | ||
|
||
import java.util.Scanner; | ||
|
||
public class Pattern7 { | ||
public static void main (String[] args) { | ||
System.out.println("/* ===== Pattern #7 ===== */"); | ||
Scanner input = new Scanner(System.in); | ||
int n = input.nextInt(), i, j; | ||
|
||
// Print upper half | ||
for (i=1; i<=n; i++) { | ||
for (j=1; j<=2*n; j++) { | ||
|
||
// Print upperleft pattern | ||
if (i+j <= n+1) | ||
System.out.print("*"); | ||
else | ||
System.out.print(" "); | ||
|
||
// Print upperright pattern | ||
if (i>j-n) | ||
System.out.print(" "); | ||
else | ||
System.out.print("*"); | ||
} | ||
System.out.println(""); | ||
} | ||
|
||
// Print lower half | ||
for (i=1; i<=n; i++) { | ||
for (j=1; j<=2*n; j++) { | ||
|
||
// Print lower left pattern | ||
if (j>i) | ||
System.out.print(" "); | ||
else | ||
System.out.print("*"); | ||
|
||
// Print lower right pattern | ||
if (i+j < 2*n+1) | ||
System.out.print(" "); | ||
else | ||
System.out.print("*"); | ||
} | ||
System.out.println(""); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/** | ||
* @author MadhavBahlMD | ||
* @date 26/12/2018 | ||
*/ | ||
|
||
/** | ||
* input = 5 | ||
* | ||
* * * | ||
* * * * * | ||
* * * * * * * | ||
* * * * * * * * * | ||
* * * * * * * * * * * | ||
* * * * * * * * * * * | ||
* * * * * * * * * | ||
* * * * * * * | ||
* * * * * | ||
* * * | ||
*/ | ||
|
||
import java.util.Scanner; | ||
|
||
public class Pattern8 { | ||
public static void main(String[] args) { | ||
System.out.println("/* ===== Pattern #8 ===== */"); | ||
Scanner input = new Scanner(System.in); | ||
int n = input.nextInt(), i, j; | ||
|
||
// Print upper pattern | ||
for (i=1; i<=n; i++) { | ||
for (j=1; j<=2*n; j++) { | ||
if (j<=n) { | ||
if (i<j) System.out.print(" "); | ||
else System.out.print("* "); | ||
} else { | ||
if (i+j < 2*n + 1) System.out.print(" "); | ||
else System.out.print("* "); | ||
} | ||
} | ||
System.out.println(""); | ||
} | ||
|
||
// Print lower pattern | ||
for (i=1; i<=n; i++) { | ||
for (j=1; j<=2*n; j++) { | ||
if (j<=n) { | ||
if (i+j>n+1) System.out.print(" "); | ||
else System.out.print("* "); | ||
} else { | ||
if (i > j-n) System.out.print(" "); | ||
else System.out.print("* "); | ||
} | ||
} | ||
System.out.println(""); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/** | ||
* @author MadhavBahlMD | ||
* @date 26/12/2018 | ||
*/ | ||
|
||
function pattern1 (num) { | ||
console.log ("/* ===== Pattern #1 ===== */"); | ||
|
||
for (let i=1; i<=num; i++) { | ||
// we will store the output for each line in a string | ||
// since console.log would print and take the pointer to next line | ||
let currentLine = ''; | ||
for(let j=1; j<=i; j++) { | ||
currentLine += j + ' '; | ||
} | ||
console.log (currentLine); | ||
} | ||
} | ||
|
||
pattern1(5); |
Oops, something went wrong.