Please help me with this code . Im using for loops here . there is some error in else part

package pattern;

public class Pattern2 {

public static void main(String[] args) {

	int n = 7;
	int r = n/2;

	for (int i = 1; i <= n; i++) {
		
		if(i<=r) {

		for (int j = 1; j <=r-i+1; j++) {

			System.out.print("* ");
		}

		for (int j = 1; j <= 2 * i - 1; j++) {
			System.out.print("  ");
		}
		
		for (int j = 1; j <=r-i+1; j++) {

			System.out.print("* ");
		}
		

		
		
		System.out.println();

		}else if(i==r+1) {
			
			System.out.println();

}
else {

			for(int j = 1 ; j<=i-n+r ; j++) {
				System.out.print("* ");
			}
			
			for(int j=1 ; j<=r+2-i; j++ ) {
				System.out.print("  ");
			}
			
			for(int j =1 ; j<=i-n+r; j++) {
				System.out.print("* ");
			}
			
			System.out.println();
		
		}
	}

}

}

your approach is fine
error is due to the calculation in the star and space point

i will suggest u to pls use the nsp(no. of space) and nst(no. of stars) varibles
instead of calculating these values using the other varibles

becoz sometimes it is very difficult for you to find no. of star and space in the given pattern.