Week 3 Assignment

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

WEEK 3 ASSIGNMENT • Pattern 1 package com.company.

WEEK3; public class pattern1 { public


static void main(String[] args) { int n=4; for (int i = 0; i <n; i++) { for (int j = 0; j <n; j++)
{ System.out.print("*"); } System.out.println(); } } } • Pattern2 package com.company.WEEK3; public
class pattern2 { public static void main(String[] args) { int n=4; //first one for (int i = 1; i <=n; i++) { for
(int j = 1; j <= n; j++) { System.out.print(j); } System.out.println(); } System.out.println(); //second one
for (int i = 1; i <=n; i++) { for (int j = 1; j <= n; j++) { System.out.print(i); } System.out.println(); } } }
• Pattern 3 package com.company.WEEK3; public class pattern3 { public static void main(String[]
args) { int n=4; //first one for (int i = 4; i >0; i--) { for (int j = 4; j >0; j--) { System.out.print(j); //
System.out.print(i); } System.out.println(); } System.out.println(); //second one for (int i = 4; i >0; i--)
{ for (int j = 4; j >0; j--) { System.out.print(i); } System.out.println(); } } } • Pattern 4 package
com.company.WEEK3; public class pattern4 { public static void main(String[] args) { int n=4; for (int i =
4; i >0; i--) { for (int j = 1; j <=i; j++) { System.out.print("*"); } System.out.println(); } } }
• Pattern 5 package com.company.WEEK3; public class pattern5 { public static void main(String[]
args) { int n=4; //first one for (int i = 4; i >0; i--) { for (int j = 1; j <=i; j++) { System.out.print(i); }
System.out.println(); } System.out.println(); //second one for (int i = 4; i >0; i--) { for (int j = 1; j <=i; j++)
{ System.out.print(j); } System.out.println(); } } } • Pattern 6 package com.company.WEEK3; public
class pattern6 { public static void main(String[] args) { int n=4; //first one for (int i = 1; i <=n; i++) { for
(int j = i; j <=n; j++) { System.out.print(i); } System.out.println(); } System.out.println(); //second one for
(int i = 1; i <=n; i++) { for (int j = n; j >=i; j--) { System.out.print(j); } System.out.println(); } } }
• Pattern 7 package com.company.WEEK3; public class pattern7 { public static void main(String[]
args) { int n=4; //first one for (int i = 1; i <=n; i++) { for (int j = 1; j <=n; j++) { char ch= (char) ('A' +i -1);
System.out.print(ch); } System.out.println(); } System.out.println(); //second one for (int i = 1; i <=n; i+
+) { for (int j = 1; j <=n; j++) { char ch= (char) ('D' - i +1); System.out.print(ch); } System.out.println(); } }
} • Pattern 8 package com.company.WEEK3; public class pattern8 { public static void main(String[]
args) { int n=4; //first one for (int i = 4; i >0; i--) { for (int j = 1; j <=i; j++) { char ch= (char) ('A' + i - 1);
System.out.print(ch); } System.out.println(); } System.out.println(); //second one for (int i = 4; i >0; i--)
{ for (int j = 1; j <=i; j++) { char ch= (char) ('A' +j -1); System.out.print(ch);
} System.out.println(); } System.out.println(); //third one for (int i = 1; i <=n; i++) { for (int j = n; j >=i; j--)
{ char ch= (char) ('A' +j -1); System.out.print(ch); } System.out.println(); } } } • Pattern 9 package
com.company.WEEK3; public class pattern9 { public static void main(String[] args) { int n=4; //first one
for (int i = 4; i >0; i--) { int space=n-i; while (space>=0) { System.out.print(" "); space--; } for (int j = 1; j
<=i; j++) { System.out.print(j); } System.out.println(); } System.out.println(); //second one for (int i = 1; i
<=n; i++) { int space=i-1; while (space>=0) { System.out.print(" "); space--; } for (int j = n; j >=i; j--)
{ System.out.print(j); } System.out.println(); } } }
• Pattern 10 package com.company.WEEK3; public class pattern10 { public static void main(String[]
args) { int n=4; for (int i = 1; i <=n; i++) { int space=i-1; while (space>0) { System.out.print(" "); space--;
} for (int j = 1; j <=i; j++) { System.out.print("*"); } System.out.println(); } for (int i = 4; i >0; i--) { int
space=n-1; while (space>n-i+1) { System.out.print(" "); space--; } for (int j = 1; j <i; j++)
{ System.out.print("*"); } System.out.println(); } } } • Pattern 11 package com.company.WEEK3; public
class pattern11 { public static void main(String[] args) { int n=4; for (int i = 1; i <=n; i++) { int space=n-i;
while (space>0) { System.out.print(" "); space--; } for (int j = 1; j <=i; j++) { System.out.print("* "); }
System.out.println(); } } } • Pattern 12 package com.company.WEEK3; public class pattern12 { public
static void main(String[] args) { int n=4; for (int i = 1; i <=n; i++) { int space=n-i; while (space>0)
{ System.out.print(" "); space--; } for (int j = 1; j <=i; j++) { System.out.print("* "); }
System.out.println(); } for (int i = 4; i >0; i--) { int space=1; while (space<=n-i+1) { System.out.print(" ");
space++; } for (int j = 1; j <i; j++) { 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