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 6 of 6

Thread: Hello there:-)

  1. #1
    Junior Member
    Join Date
    Feb 2012
    Posts
    3
    My Mood
    Sneaky
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Cool Hello there:-)

    Hi

    I just started a "Intro to Java" class and need lots of help! I have taken C++ but that was over three years ago . I am having a problem with this asterisk homework, and if anyone could give me some help I would appreciate it.

    Here is what I am supposed to display in basic frame:


    If user inputs 5 then,


    *
    **
    ***
    ****
    *****
    ****
    ***
    **
    *


    I have the top portion of the triangle, however no matter what I do I cannot get the bottom half......................Pleaseeeeee Help!
    Thanks,
    Amanda
    Last edited by HazelEyedGirl; February 26th, 2012 at 02:53 PM.

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,105
    Thanks
    48
    Thanked 2,153 Times in 2,126 Posts

    Default Re: Hello there:-)

    You should post your code with your questions.
    The number of *s on each line changes. What is the criteria for when the number increases and for when the number decreases? How is the line # of the line you are printing one related to the number of *s to go on that line?

  3. #3
    Junior Member
    Join Date
    Feb 2012
    Posts
    3
    My Mood
    Sneaky
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Hello there:-)

    The input # should equal the number of *'s in the middle of the "arrow head". It should begin by increasing from * to ** to *** to the number the user inputs. Then it should decrease in the same way. I have tried soooo many things. But everytime I mess with it I either get a straight line of *, or a infinite loop of them.......................grr!



    Scanner input = new Scanner(System.in);
    int starlength;

    System.out.print("Please enter the number of *'s to span the length of your arrowhead:");
    starlength=input.nextInt();
    int row=1;
    while(row<=starlength)
    {
    int star=1;
    while(star<=row)
    {
    System.out.print("*");
    star++;
    }
    System.out.println();
    row++;

    }}}



    The output if the user inputs 5 is:

    *
    **
    ***
    ****
    *****



    So any advice? Btw, thanks for responding Only girl in my class and I feel like the slow one

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,105
    Thanks
    48
    Thanked 2,153 Times in 2,126 Posts

    Default Re: Hello there:-)

    How does your code determine when it should decrease the number of *s on a line?

    }s should not be nested all on one line. They should go on their own lines and be beneath the line with the beginning {
      {
           // some code 
           {
              // some more
           }
      }

    Please Edit your post and wrap your code with[code=java]<YOUR CODE HERE>[/code] to get highlighting

  5. #5
    Junior Member
    Join Date
    Feb 2012
    Posts
    3
    My Mood
    Sneaky
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Hello there:-)

    That's the problem, I dont know how to make it decrease. I've tried the whole -- for each vari. but its not working. I'm trying to figure out what i need to add in order to make it decrease. For? another While?



    * author Amanda
     */
    public class Homework {
     
        /**
         *
         */
        public static void main(String[] args) {
     
        Scanner input = new Scanner(System.in); 
    int starlength;
     
    System.out.print("Please enter the number of *'s to span the length of your arrowhead:");
    starlength=input.nextInt();
    int row=1;
    while(row<=starlength)
    {
    int star=1;
    while(star<=row)
    {
    System.out.print("*");
    star++;
    }
    System.out.println();
    row++;
    {
     
    }
    }
    }
    }
    Last edited by HazelEyedGirl; February 26th, 2012 at 04:57 PM.

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,105
    Thanks
    48
    Thanked 2,153 Times in 2,126 Posts

    Default Re: Hello there:-)

    Please edit your code and format it properly. Each nesting level within a set of {} should be indented 3-4 spaces
    The } should NOT be directly beneath each other. See the simple example in my last post.

    What if you used two loops? One for when the number increases and one for when it decreases.