0% found this document useful (0 votes)
33 views7 pages

Week 3 Assignment

Uploaded by

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

Week 3 Assignment

Uploaded by

reverbtales
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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