hi new to java - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

hi new to java

garethnicoosgarethnicoos Posts: 4Member
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
Sign In or Register to comment.