0% found this document useful (0 votes)
10 views

Allpatterns

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Allpatterns

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

public class Allpatterns {

public static void main(String[] args) {


int n = 5;
// Triangle(n);
// rightAngleTriangle2(n);
// hollowSquare(n);
// hollowRightAngleTriangle3(n);
// diagnol("rahul");
rightAngleTriangle4(n);
}

static void square(int n) {


for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
System.out.print("* ");
}
System.out.println();
}
}

static void rightAngleTriangle(int n) {


for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j++) {
System.out.print("*");
}
System.out.println();
}
}

static void rightAngleTriangle1(int n) {


for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n - i + 1; j++) {
System.out.print("*");
}
System.out.println();
}
}

static void rightAngleTriangle2(int n) {


for (int i = 1; i <= n; i++) {
for (int j = 2; j <= n - i + 1; j++) {
System.out.print(" ");
}
for (int j = 1; j <= i; j++) {
System.out.print("*");
}
System.out.println();
}
}

static void Triangle(int n) {


for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n - i + 1; j++) {
System.out.print(" ");
}
for (int j = 1; j <= i; j++) {
System.out.print("* ");
}
System.out.println();
}
}

static void rightAngleTriangle4(int n) {


for (int i = 1; i <= n; i++) {
for (int j = 2; j <= i; j++) {
System.out.print(" ");
}
for (int j = 1; j <= n - i + 1; j++) {
System.out.print("*");
}
System.out.println();
}
}

// Hollows
static void hollowSquare(int n) {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (i == 1 || j == 1 || i == n || j == n) {
System.out.print("* ");
} else {
System.out.print(" ");
}
}
System.out.println();
}
}

static void hollowRightAngleTriangle(int n) {


for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j++) {
if (j == 1 || i == n || i == j) {
System.out.print("* ");
} else {
System.out.print(" ");
}
}
System.out.println();
}
}

static void hollowRightAngleTriangle1(int n) {


for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n - i + 1; j++) {
if (i == 1 || j == 1 || j == n - i + 1) {

System.out.print("* ");
} else {
System.out.print(" ");
}
}
System.out.println();
}
}

static void hollowRightAngleTriangle2(int n) {


for (int i = 1; i <= n; i++) {
for (int j = 2; j <= i; j++) {
System.out.print(" ");
}
for (int j = 1; j <= n - i + 1; j++) {
if (i == 1 || j == 1 || j == n - i + 1) {

System.out.print("*");
} else {
System.out.print(" ");
}
}
System.out.println();
}
}

static void hollowRightAngleTriangle3(int n) {


for (int i = 1; i <= n; i++) {
for (int j = 2; j <= n - i + 1; j++) {
System.out.print(" ");
}
for (int j = 1; j <= i; j++) {
if (j == 1 || i == j || i == n) {
System.out.print("*");
} else {
System.out.print(" ");
}
}
System.out.println();
}
}

static void diagnol(int n) {


for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (i == j || j == n - i + 1) {
System.out.print("*");
} else {
System.out.print(" ");
}
}
System.out.println();
}
}

static void diagnol(String n) {


for (int i = 0; i < n.length(); i++) {
for (int j = 0; j < n.length(); j++) {
if (i == j || j == n.length() - i - 1) {
System.out.print(n.charAt(i));
} else {
System.out.print(" ");
}
}
System.out.println();
}
}

You might also like