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

java week 10

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)
10 views

java week 10

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/ 6

Week =10

1).

public class PatternExample {

public static void main(String[] args) {

int rows = 4;

int columns = 5;

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

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

System.out.print("*");

System.out.println();

2). public class Main {

public static void main(String[] args) {

int n = 5;

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

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

System.out.print("*");

System.out.println();

3). public class Main {

public static void main(String[] args) {

int n = 5;
for (int i = 1; i <= n; i++) {

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

System.out.print("*");

System.out.println();

4). public class Main {

public static void main(String[] args) {

int n = 5;

for (int i = n; i >= 1; i--) {

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

System.out.print("*");

System.out.println();

5). public class Main {

public static void main(String[] args) {

int n = 5;

for (int i = 1; i <= n; i++)

for (int j = 1; j <= 5; j++) {

System.out.print("*");

System.out.println();

}
}

6). public class Main {

public static void main(String[] args) {

int n = 11;

for (int i = 1; i <= n / 2 + 1; i++) {

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

System.out.print("*");

System.out.println();

for (int i = n / 2 + 2; i <= n; i++) {

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

System.out.print("*");

System.out.println();

7). public class Main {

public static void main(String[] args) {

int n = 5;

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

// Inner loop to print '*' characters

for (int j = 1; j <= n; j++) {

if (i == 1 || i == n || j == 1 || j == n) {

System.out.print("*");

} else {

System.out.print(" ");

}
}

System.out.println();

8). public class Main {

public static void main(String[] args) {

int n = 5;

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

for (int j = 1; j <= n; j++) {

if (j == 1 || j == n || i == n) {

System.out.print("* ");

} else {

System.out.print(" ");

System.out.println();

9). public class Main {

public static void main(String[] args) {

int n = 5;

for (int i = n; i >= 1; i--) {

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

System.out.print("*");

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


System.out.print(" ");

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

System.out.print("*");

System.out.println();

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

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

System.out.print("*");

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

System.out.print(" ");

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

System.out.print("*");

System.out.println();

10). public class Main {

public static void main(String[] args) {

int n = 7; // Number of rows

for (int i = 1; i <= n / 2; i++) {

System.out.println("*");

}
for (int i = 1; i <= n; i++) {

System.out.print("*");

System.out.println();

for (int i = 1; i <= n / 2; i++) {

System.out.println("*");

You might also like