Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Hi new to java trying to do something new :) any help would be appreciated!

  1. #1
    Junior Member
    Join Date
    Nov 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Hi new to java trying to do something new :) any help would be appreciated!

    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


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Hi new to java trying to do something new :) any help would be appreciated!

    What are the rules for the number of leading .s, middle *s and trailing .s for each row that you print?
    Write the the rules for each row and see what the pattern is that you can use to print the correct number of characters on each row.

  3. #3
    Member
    Join Date
    Mar 2011
    Posts
    32
    My Mood
    Worried
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Hi new to java trying to do something new :) any help would be appreciated!

    Hey,

    Hi,

    I am also new to this. I also appreciate if you guys will help me.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Hi new to java trying to do something new :) any help would be appreciated!

    You need to do some work with a paper and pencil to get a design for your program.
    I suggested in post#2 a way to look at the problem.
    For each line/row you need to see how many of each character is printed and in what order and then see what the relationship is to what row you are printing on.

Similar Threads

  1. Help really appreciated
    By Thermal_Vent in forum Java Theory & Questions
    Replies: 1
    Last Post: November 15th, 2010, 08:42 AM
  2. Help would be so much appreciated new Irish Java programmer
    By joan in forum Member Introductions
    Replies: 1
    Last Post: September 29th, 2010, 02:24 PM
  3. any help is much appreciated
    By Schmitz14 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 8th, 2009, 07:51 PM
  4. nextLine problems, any help appreciated
    By Schmitz14 in forum File I/O & Other I/O Streams
    Replies: 2
    Last Post: October 5th, 2009, 01:23 AM
  5. Need a little help. would be greatly appreciated
    By ryan29121 in forum Java Theory & Questions
    Replies: 4
    Last Post: September 27th, 2009, 02:03 PM

Tags for this Thread