0% found this document useful (0 votes)
11 views4 pages

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)
11 views4 pages

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

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy