Hi i am trying to complete this task:

Write an a Java application which prints a diamond in a
square grid of dots whose side length is input to the
application. The side of the square must be an odd
number. If the input data is invalid an error message is
output. For example, if the input data was 10 then the
error message
Size (10) invalid must be odd
would be printed. If the input data was -5 then the error
message
Sides of square must be positive
would be printed like this:
..*..
.*.*.
*...*
.*.*.
..*..
any help would be greatly appreciated here is the code I already have the following code:

class Main
{
int i , j , k, n = 5; //n is the number of lines and i,j are used for loops

k=(n==0)?n-1:n; //k is used to control the number of spaces to be printed

for( i = 0 ; i < n/2 ; i++ ) //for the top portion of the diamond
{
for( j = 0 ; j < k / 2 - i ; j++ ) //print required spaces
System.out.print(" ");

for ( j = 0 ; j < i * 2 + 1 ; j++ ) //print required stars
System.out.print("*");

System.out.println(); //line break after the end of a line
}

if( n % 2 != 0) //if the number of lines is odd
{
for( i = 0 ; i < n ; i++ ) //print extra asterisks in the middle
System.out.print("*");

System.out.println(); //line break
}

for( i = n/2-1 ; i >= 0 ; i-- ) //for the bottom portion of the diamond
{
for( j = 0 ; j < k/2 - i ; j++ ) //print required spaces
System.out.print(".");

for( j = 0 ; j < i*2+1 ; j++ ) //print required stars
System.out.print("*");

System.out.println(); //line break after the end of a line
}
} //end main
} //end class diamond