I want to print pattern of stars in ZigZag manner....i am unable to break the pattern as zigzag. please help me in doing this public class Pattern3_1 {
public static void main(String[] args) {
Pattern3_1 pattern = new Pattern3_1();
pattern.printPattern(5,5);***strong text***
}
public void printPattern(int rows,int coloumns) {
int index = 0;
for (int i = 0; i < rows; i++) {
if (index < rows /2) {
for (int j = 0; j < coloumns; j++) {
System.out.print("*");
}
System.out.println();
for (int k = 0; k < i + 1; k++) {
System.out.print(" ");
}index++;
}
else {
for (int j = 0; j < coloumns; j++) {
System.out.print("*");
}
System.out.println();
for (int k = i + 1; k < rows; k++) {
System.out.print(" ");
}
}
}
}
} output:
*****
*****
*****
when i try this way i am not getting in ZIGZAG way.... please help me in doing this...........
Aucun commentaire:
Enregistrer un commentaire