hi, I am trying to complete the following task (purely for fun) I would really appreciate it if someone could adapt my code:
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
Here is my code i have got:
public class Stars
{
public static void main(String[] args)
{
System.out.println("Enter size of Diamond");
System.out.println();
int longestRow = BIO.getInt();
for(int row=1 ; row<=longestRow ; ++row)
{
int i = (2*row) - 1;
if(i>longestRow) i = 2*(longestRow-row+1) - 1;
for(int j=0 ; j<(longestRow-i)/2 ; ++j) System.out.print(".");
for(int j=0 ; j<i ; ++j) System.out.print("*");
for(int j=0 ; j<(longestRow-i)/2 ; ++j) System.out.print(".");
System.out.println();
}
}
}
this looks like this when ran:
5
..*..
.***.
*****
.***.
..*..
I am trying to make it look like this:
..*..
.*.*.
*...*
.*.*.
..*..
Thanks Gareth