butterfly pattern program in java
import java.util.Scanner;
public class ButterFly {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter n value");
int n=sc.nextInt();
int sp=2*n-1,st=0;
for(int i=1;i<=2*n-1;i++){
if(i<=n){
sp=sp-2;
st++;
}
else{
sp=sp+2;
st--;
}
for(int j=1;j<=st;j++){
System.out.print("*");
}
for(int k=1;k<=sp;k++){
System.out.print(" ");
}
for(int l=1;l<=st;l++){
if(l!=n)
System.out.print("*");
}
System.out.println();
}
}
}
Also in Java:
- fragment button nullpointerexception
- how to create a button in java
- butterfly pattern program in java
- cgange background from button click java fx
- java append to array
- get value textfield java
- store string elements in character array in java
- write an infinite loop java
- remove last character from string java
- java stream sort
- java int to string
- loop java
- select photo from camera android
- java for
- stack class in java
- indexof java
- HOW TO SUPRESS sonar warning in java code
- java null pointer exception
- java parse xml string
- java read string input
- delete element from arraylist
- java int array
- connecting to h2 database from java
- when super add by constructor in java