Results 1 to 6 of 6

Thread: java problem

  1. #1
    Mj Shine is offline Member
    Join Date
    Aug 2009
    Posts
    1
    Rep Power
    0

    Question java problem

    i need help for this problem...


    "write a program that ask the user to enter the size of a triangle (1 to 50).then print the triangle by printing a series of lines consisting of asterisks.the first line will have 1 asterisk, the next two will have two and so on....with each line having one more asterisk than the previous line up to the number entered by the user.on the next line print one less asterisk and continue by decreasing the number of esterisk by 1 for each successive line until any one asterisk is printed."
    hint: use nested loops, the outside loop controls the number of lines and the inside loops controls the number of asterisk to print on a line.

    i hope, anyone will help me on this problem...pls....

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    What you've done is to post your entire assignment without showing what work you've done, and that is not how to get help here (or at any forum). For one, we have no idea what you're having trouble with, so we won't know how to advise you. For another, it suggests that you want someone to post a complete solution, thereby doing your homework for you, and I know that this was not your intent.

    So please try to solve the problem first, and then post what you've done using code tags (see my signature), and then ask a specific question. Do this and you'll have many folks willing to help you.

    Much luck!

  3. #3
    HosHos's Avatar
    HosHos is offline Member
    Join Date
    Aug 2009
    Posts
    10
    Rep Power
    0

    Thumbs up Here it is

    int input; //input from user

    //Nested Loops
    int count=0;

    for(int i=0;i<input;i++)
    {
    for(int j=0;j<i;j++)
    {
    System.out.print("*");
    }
    System.out.println();
    count=i;
    }

    if(count>=input-1)

    {

    for(int k=count;k>=0;k--)
    {
    for(int j=0;j<=k;j++)
    {
    System.out.print("*");
    }
    System.out.println();
    }

    }
    ================================================== ========
    If the input =10;the result will be ass following:

    *
    **
    ***
    ****
    *****
    ******
    *******
    ********
    *********
    ********** // 10(*)'s
    *********
    ********
    *******
    ******
    *****
    ****
    ***
    **
    *
    HosHos :cool:
    hoss.2011@hotmail.com

  4. #4
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default

    Read the faq about using code tags. It makes the code much easier to read. Here is a link:
    Java Forums - BB Code List

  5. #5
    emceenugget is offline Senior Member
    Join Date
    Sep 2008
    Posts
    564
    Rep Power
    6

    Default

    this is where you state what you actually need help with in your code...

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Just giving away a code is not make sense lol. Better to give some guide first of all, otherwise our thread starter wont tryout anything new. That's not the way to learn.

    Quote Originally Posted by HosHos View Post
    int input; //input from user

    //Nested Loops
    int count=0;

    for(int i=0;i<input;i++)
    {
    for(int j=0;j<i;j++)
    {
    System.out.print("*");
    }
    System.out.println();
    count=i;
    }

    if(count>=input-1)

    {

    for(int k=count;k>=0;k--)
    {
    for(int j=0;j<=k;j++)
    {
    System.out.print("*");
    }
    System.out.println();
    }

    }
    ================================================== ========
    If the input =10;the result will be ass following:

    *
    **
    ***
    ****
    *****
    ******
    *******
    ********
    *********
    ********** // 10(*)'s
    *********
    ********
    *******
    ******
    *****
    ****
    ***
    **
    *

Similar Threads

  1. Help, java problem
    By Suriman in forum New To Java
    Replies: 4
    Last Post: 03-09-2009, 04:26 PM
  2. problem with java nio
    By andrei stoiculescu in forum Networking
    Replies: 3
    Last Post: 02-02-2009, 03:35 PM
  3. Java problem
    By grend in forum New To Java
    Replies: 5
    Last Post: 08-18-2008, 11:44 PM
  4. Problem in java
    By saytri in forum New To Java
    Replies: 6
    Last Post: 01-09-2008, 04:13 PM
  5. java SE 6 problem
    By techlance in forum Java Applets
    Replies: 1
    Last Post: 06-28-2007, 10:10 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •