Q:

I need to make a pyramid with for loops and user input

Okay so, I need to make a pyramid with using for loops, and I need the user to input the base of the triangle.  I have it mostly completed (i think) but I need some help because the output doesn't give the right base(bottom layer) of it, it gives two less * than inputted... can someone help me fix this please?  Here is the code I have so far:
import java.util. Scanner;

public class Client {
    public static void pyramid(){
        int x;
        Scanner console = new Scanner(System.in);
        System.out.println("What is the base?: "); 
        x = console.nextInt();
        for (int i=1; i < x; i += 2){
            for (int k=0; k < (4 - i / 2); k++){
                System.out.print(" ");
            }
            for (int j=0; j< i ; j++){
                System.out.print("*");
            }
            System.out.println("");
        }
    }

    public static void main(String[] args) {
        pyramid();
    }
}

A:

Try this;
    public static void pyramid() {
        int x;
        Scanner console = new Scanner(System.in);
        System.out.println("What is the base?: "); 
        x = console.nextInt();
        for (int i = 1; i <= x; i=i+2) {
            int spaceCount = (x - i)/2;  // how many space I will put for 5 firstly 2 spaces, then 1 space
            for(int j = 0; j< x; j++) {
                if(j < spaceCount || j >= (x - spaceCount)) {
                    System.out.print(" "); // put spaces before *
                } else {
                    System.out.print("*");
                }
            }
            System.out.println(); 
        }

    }

Output for 5;
What is the base?:  
5
  *  
 *** 
*****

