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

Class Xpattern

This Java code defines a class called Xpattern with a main method that uses nested for loops to print out a cross pattern of asterisks. The inner loop iterates from 1 to 5 and prints an asterisk if the difference or sum of the counters i and j is equal to 0 or 6, otherwise it prints a space; this is repeated over 5 lines printed with each iteration of the outer loop.

Uploaded by

Anuj Jain
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)
28 views

Class Xpattern

This Java code defines a class called Xpattern with a main method that uses nested for loops to print out a cross pattern of asterisks. The inner loop iterates from 1 to 5 and prints an asterisk if the difference or sum of the counters i and j is equal to 0 or 6, otherwise it prints a space; this is repeated over 5 lines printed with each iteration of the outer loop.

Uploaded by

Anuj Jain
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/ 1

class Xpattern

public static void main()

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

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

if(j-i==0||i+j==6)

System.out.print("*");

else

System.out.print(" ");

System.out.println();

You might also like