Untitled
CODEWITHKARANTIGER
plain_text
a year ago
972 B
11
Indexable
package pattern;
class fullbutterfly{
public static void main(String[] args) {
int n = 4;
int spaces = (2 * n) - 2;
int stars = 1;
int currentline = 1;
while (currentline <= n) {
// print stars
for (int i = 1; i <= stars; i++) {
System.out.print("* ");
}
//print spaces
for (int i = 1; i <= spaces; i++) {
System.out.print(" ");
}
//print stars
for (int i = 1; i <= stars; i++) {
System.out.print("* ");
}
// prepare for next line
System.out.println();
if (currentline<n)
{
stars++;
spaces = spaces - 2;
}
else {
stars--;
spaces = spaces+1;
}
currentline++;
}
}
}Editor is loading...
Leave a Comment