Skip to content
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

Feat: Add Pattern Printing Programs in JAVA #11

Open
wants to merge 1 commit into
base: main
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
29 changes: 29 additions & 0 deletions Pattern-Printing/Pattern1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import java.util.Scanner;

public class Pattern1 {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

System.out.print("Enter the number of rows you want to print: ");

int input = Integer.parseInt(sc.nextLine()); // Converts the input to an integer

System.out.println();

for (int row = input; row >= 1; --row) {

for (int col = 1; col <= row; ++col) {

System.out.print("*");

}

System.out.println();

}

}

}
79 changes: 79 additions & 0 deletions Pattern-Printing/Pattern10.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import java.util.Scanner;

public class Pattern10 {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

System.out.print("Enter the number of rows you want to print: ");

int input = Integer.parseInt(sc.nextLine()); // Converts the input to an integer

System.out.println();

int i, j;

for (i = 1; i <= input; i++) {

for (j = input; j > i; j--) {

System.out.print(" ");

}

System.out.print("*");

for (j = 1; j < (i - 1) * 2; j++) {

System.out.print(" ");

}

if (i == 1) {

System.out.println("");

}

else {

System.out.println("*");

}

}

for (i = (input - 1); i >= 1; i--) {

for (j = input; j > i; j--) {

System.out.print(" ");

}

System.out.print("*");

for (j = 1; j < (i - 1) * 2; j++) {

System.out.print(" ");

}

if (i == 1) {

System.out.println("");

}

else {

System.out.println("*");

}

}

}

}
29 changes: 29 additions & 0 deletions Pattern-Printing/Pattern2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import java.util.Scanner;

public class Pattern2 {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

System.out.print("Enter the number of rows you want to print: ");

int input = Integer.parseInt(sc.nextLine()); // Converts the input to an integer

System.out.println();

for (int row = 1; row <= input; ++row) {

for (int col = 1; col <= row; ++col) {

System.out.print("*");

}

System.out.println();

}

}

}
39 changes: 39 additions & 0 deletions Pattern-Printing/Pattern3.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import java.util.Scanner;

public class Pattern3 {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

System.out.print("Enter the number of rows you want to print: ");

int input = Integer.parseInt(sc.nextLine()); // Converts the input to an integer

int count = input - 1;

System.out.println();

for (int k = 1; k <= input; k++) {

for (int i = 1; i <= count; i++) {

System.out.print(" ");

}

count--;

for (int i = 1; i <= 2 * k - 1; i++) {

System.out.print("*");

}

System.out.println();

}

}

}
61 changes: 61 additions & 0 deletions Pattern-Printing/Pattern4.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import java.util.Scanner;

public class Pattern4 {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

System.out.print("Enter the number of rows you want to print: ");

int input = Integer.parseInt(sc.nextLine()); // Converts the input to an integer

int count = input - 1;

System.out.println();

for (int k = 1; k <= input; k++) {

for (int i = 1; i <= count; i++) {

System.out.print(" ");

}

count--;

for (int i = 1; i <= 2 * k - 1; i++) {

System.out.print("*");

}

System.out.println();

}

count = 1;

for (int k = 1; k <= input - 1; k++) {

for (int i = 1; i <= count; i++) {

System.out.print(" ");

}

count++;

for (int i = 1; i <= 2 * (input - k) - 1; i++) {

System.out.print("*");

}

System.out.println();

}

}

}
35 changes: 35 additions & 0 deletions Pattern-Printing/Pattern5.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import java.util.Scanner;

public class Pattern5 {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

System.out.print("Enter the number of rows you want to print: ");

int input = Integer.parseInt(sc.nextLine()); // Converts the input to an integer

System.out.println();

for (int i = 1; i <= input; i++) {

for (int j = 1; j <= input - i; j++) {

System.out.print(" ");

}

for (int k = 1; k <= i; k++) {

System.out.print("*");

}

System.out.println("");

}

}

}
48 changes: 48 additions & 0 deletions Pattern-Printing/Pattern6.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import java.util.Scanner;

public class Pattern6 {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

System.out.print("Enter the number of rows you want to print: ");

int input = Integer.parseInt(sc.nextLine()); // Converts the input to an integer

System.out.println();

for (int i = 0; i < input; ++i) {

for (int j = 0; j <= i; ++j) {

System.out.print("*");

}


if (i != input - 1) {

System.out.print(" ");

}

else {

System.out.print(" *");

}

for (int j = 0; j <= i; ++j) {

System.out.print("*");

}

System.out.println();

}

}

}
51 changes: 51 additions & 0 deletions Pattern-Printing/Pattern7.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import java.util.Scanner;

public class Pattern7 {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

System.out.print("Enter the number of rows you want to print: ");

int input = Integer.parseInt(sc.nextLine()); // Converts the input to an integer

System.out.println();

for (int i = 0; i < input; i++) {

if (i == 0 || i == 6) {

for (int j = 0; j < input; j++) {

System.out.print("*");

}

System.out.println();

}

if (i >= 1 && i <= 5) {

for (int j = 0; j < input; j++) {

if (j == 0 || j == 6) {

System.out.print("*");

}

else if (j >= 1 && j <= 5) {

System.out.print(" ");

}
}
System.out.println();
}
}

}

}
Loading