0% found this document useful (0 votes)
3 views2 pages

Java Star Pattern Generation Code

The document contains Java code for two classes, Patterns and AdvancedPatterns, which generate different star patterns based on specified conditions using nested loops. The Patterns class creates basic patterns based on the relationship between the row and column indices, while the AdvancedPatterns class generates a more complex pattern with additional conditions. Both classes utilize a grid of size 'n' to control the output of the star patterns.

Uploaded by

bhalkeshiva32
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)
3 views2 pages

Java Star Pattern Generation Code

The document contains Java code for two classes, Patterns and AdvancedPatterns, which generate different star patterns based on specified conditions using nested loops. The Patterns class creates basic patterns based on the relationship between the row and column indices, while the AdvancedPatterns class generates a more complex pattern with additional conditions. Both classes utilize a grid of size 'n' to control the output of the star patterns.

Uploaded by

bhalkeshiva32
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

public class Patterns {

public static void main(String[] args) {


int n=9;
f or(int i = 0;i<n;i++) {
f or(int j = 0;j<n;j++) {
//condition --> i-j
if (i-j==0){
[Link]("*");
}else{
[Link](" ");
}
}
[Link]();//new line.
}

[Link]("__________________");
f or(int i = 0;i<n;i++) {
f or(int j = 0;j<n;j++) {
//condition --> i-j
if (i-j>=0){
[Link]("*");
}else{
[Link](" ");
}
}
[Link]();//new line.
}
f or(int i = 0;i<n;i++) {
f or(int j = 0;j<n;j++) {
//condition --> i-j
if (i-j<=0){
[Link]("*");
}else{
[Link](" ");
}
}
[Link]();//new line.
}
f or(int i = 0;i<n;i++) {
f or(int j = 0;j<n;j++) {
//condition --> i-j
if (i+j>=n-1){
[Link]("*");
}else{
[Link](" ");
}
}
[Link]();//new line.
}
f or(int i = 0;i<n;i++) {
f or(int j = 0;j<n;j++) {
//condition --> i-j
if (i+j==n-1){
[Link]("*");
}else{
[Link](" ");
}
}
[Link]();//new line.
}
[Link]("____________________");
f or(int i = 0;i<n;i++) {
f or(int j = 0;j<n;j++) {
//condition --> i-j
if (i+j<=n-1){
[Link]("*");
}else{
[Link](" ");
}
}
[Link]();//new line.
}
}
}

--------------------------------------------------------------------------------------------------
package [Link];

public class Advancedpratterns {

public static void main(String[] args) {


// TODO Auto-generated method stub

int n=15;
f or(int i=0; i<n; i++) {
f or(int j=0; j<n;j++) {
if (i==0 || j==0 || i==n-1 || j==n-1
|| i-j==0 || i+j==n-1 || j==n/2
|| i==n/2 || i==n/4 || i==3*n/4
|| j==n/4 ||j==3*n/4
|| i+j==(n-1)/2 || i-j==n/2
|| i-j==-(n/2) || i+j==(n-1)+n/2) {
[Link]("* ");
}else {
[Link](" ");
}
}//end of 2nd loop
[Link](); // newline
}// end of 1st loop

You might also like