Java语言输入x y的值,在控制台输出一个由*号组成的长方形

Java语言输入x y的值,在控制台输出一个由*号组成的长方形
例如

3 4
***
* *
* *
***

    public static void rectangle(int x,int y) {
        if ( x<1 || y<1){
            throw new IllegalArgumentException("");
        }
        StringBuilder sb = new StringBuilder(x);
        for (int i = 0; i < y; i++) {
            for (int j = 0; j < x; j++) {
                if (i==0 || i==y-1 || j==0 || j==x-1){
                    sb.append('*');
                }else {
                    sb.append(' ');
                }
            }
            System.out.println(sb.toString());
            sb.delete(0,sb.length());
        }
    }