Starter Java programmer
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: Starter Java programmer

Hybrid View

  1. #1
    Join Date
    Apr 2010
    Posts
    5

    Wink Starter Java programmer

    i wanted this as my program output.
    1
    1 2 1
    1 2 3 2 1
    1 2 3 4 3 2 1

    n go on n on.

    Till now i have programmed this much but not gettin the correct output...!!


    import java.util.*;
    class pyramid
    {
    public static void main(String args[])
    {
    int i,k,j,r;
    System.out.print("Enter No. of Rows : ");
    Scanner a=new Scanner(System.in);
    r=a.nextInt();
    for(i=1;i<=r;i++)
    {
    for(j=1;j<=i;j++)
    System.out.print(" "+j);
    for(k=i-1;k>=1;k--)
    System.out.print(" "+k);
    System.out.println(" ");
    }
    }
    }


    /* OUTPUT


    D:\Salil JAVA>javac pyramid.java

    D:\Salil JAVA>java pyramid
    Enter No. of Rows : 4
    1
    1 2 1
    1 2 3 2 1
    1 2 3 4 3 2 1

    D:\Salil JAVA>

    */
    I have coded most of it..
    Just missin the spaces...!!

    and can anyone help me out with

    +*
    ++**
    +++***
    ++++****
    +++++*****
    thnx waiting eagerly for ur replies...!!

  2. #2
    Join Date
    Apr 2010
    Posts
    5

    Re: Starter Java programmer

    Oops..Sorry

    for the first program the output i want is

    1
    121
    12321
    1234321
    123454321

  3. #3
    Join Date
    Apr 2010
    Posts
    5

    Re: Starter Java programmer

    ***?
    m neither able to post spaces in the main post nor in the quote...what do i do ??? (

  4. #4
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: Starter Java programmer

    Quote Originally Posted by devilasad View Post
    ***?
    m neither able to post spaces in the main post nor in the quote...what do i do ??? (
    Put it in &#91;CODE]...&#91;/CODE] tags? Use underscores and say you mean spaces?

    Experience is a poor teacher: it gives its tests before it teaches its lessons...
    Anon.
    Please use &#91;CODE]...your code here...&#91;/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

  5. #5
    Join Date
    Apr 2010
    Posts
    5

    Re: Starter Java programmer

    Quote Originally Posted by dlorde View Post
    Put it in
    Code:
    ...
    tags? Use underscores and say you mean spaces?

    Experience is a poor teacher: it gives its tests before it teaches its lessons...
    Anon.
    Thnx Anon...helpful..!!

    this is Expected o/p
    Code:
    ____1
    ___121
    __12321
    _1234321
    123454321
    __ ==> Spaces


  6. #6
    Join Date
    May 2006
    Location
    UK
    Posts
    4,474

    Re: Starter Java programmer

    The code in your first post is adding a space between each digit but the last example output you posted shows no spaces between the digits, so which one do you want?

    If you look at the relationship between the number of spaces required in the first row and the number of rows you are printing and also look at how the number of spaces changes with each row you should be able to work out how to write a for loop to add the spaces.
    Posting code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

  7. #7
    Join Date
    Apr 2010
    Posts
    5

    Re: Starter Java programmer

    Mods m extremely sorry for multireplying my own thread...
    I can't edit my posts..!
    Just to tell i wanted the o/p in the screen..!

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
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center