Results 1 to 17 of 17
Like Tree1Likes
  • 1 Post By Tolls

Thread: error in prog to display floyds triangle

  1. #1
    simar is offline Member
    Join Date
    Aug 2014
    Posts
    24
    Rep Power
    0

    Default error in prog to display floyds triangle

    i want to display triangle with for or if loop in java prog as:
    1
    2 3
    4 5 6
    7 8 9 10
    11 12 13 14 15
    .
    .
    .
    79. . . . . . . . . .91
    here is code and error file
    eror of for: E:\Java\jdk\bin>javac tri.java tri.java:16: error: reached end of file while parsing } ^ 1 error code of above error:
    Java Code:
     
    class tri 
    { 
    public static void main (String args[]) 
    {
     int i,j,a=0; for(i=1;i<=79;i++) 
    {
     for(j=1;j<=i;j++) 
    {
     a++;
     System.out.print(" ");
     System.out.print(a);
     } 
    System.out.print("\n");
     }
     }
    Last edited by simar; 08-10-2014 at 06:47 PM.

  2. #2
    simar is offline Member
    Join Date
    Aug 2014
    Posts
    24
    Rep Power
    0

    Default Re: error in prog to display floyds triangle

    here is triangle
    1
    2 3
    4 5 6
    7 8 9 10
    11 12 13 14 15
    .
    .
    79.... . . . . . . . . . .. .91

  3. #3
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,777
    Rep Power
    5

    Default Re: error in prog to display floyds triangle

    Please edit your post and reformat your code so it is properly indented.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  4. #4
    simar is offline Member
    Join Date
    Aug 2014
    Posts
    24
    Rep Power
    0

    Default Re: error in prog to display floyds triangle

    error in using of if:
    E:\Java\jdk\bin>javac triif.java
    triif.java:20: error: reached end of file while parsin
    }
    ^
    1 error

    here is code using if


    Java Code:
    class triif
    {
    public static void main (String args[])
    {
    int i,j,a=0;
    if(i<=79)
    {
    if(j<=i)
    {
    a++;
    System.out.print(" ");
    System.out.print(a);
    j++;
    }
    else
    {
    System.out.print("\n");
    i++;
    }
    }
    Last edited by simar; 08-10-2014 at 06:55 PM.

  5. #5
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,798
    Rep Power
    7

    Default Re: error in prog to display floyds triangle

    Quote Originally Posted by simar View Post
    if loop
    No such thing!

    You been asked to posted properly formatted code. Are you incapable of seeing that your code appears all one line? This makes it impossible to read.

  6. #6
    simar is offline Member
    Join Date
    Aug 2014
    Posts
    24
    Rep Power
    0

    Default Re: error in prog to display floyds triangle

    wel i tried i m copy pasting from window phone when i copy paste it , and click on save after that it automaticaly appear in single line ,,,,i dont know where the problem is,,,, i wil try once more thx for ur consultancy

  7. #7
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,798
    Rep Power
    7

    Default Re: error in prog to display floyds triangle

    Why not wait until you get on your computer and copy and paste it correctly.

  8. #8
    simar is offline Member
    Join Date
    Aug 2014
    Posts
    24
    Rep Power
    0

    Default Re: error in prog to display floyds triangle

    now help me out and plzzz first of all check the logic is it correct,,,,,,,,,,,

  9. #9
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,798
    Rep Power
    7

    Default Re: error in prog to display floyds triangle

    Now all indenting has disappeared still making it hard to read. If your code was properly indented you will probably see that your braces do not match.

  10. #10
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,651
    Blog Entries
    7
    Rep Power
    21

    Default Re: error in prog to display floyds triangle

    Quote Originally Posted by simar View Post
    wel i tried i m copy pasting from window phone when i copy paste it
    A phone is for making phone calls, not for programming; your code ends up horrible, it's a burden for us to read it and your code ends up not making sense, i.e. the code from your OP doesn't resemble the code from your reply #4 and your accompanying text is just annoying text speak that is also hardly readable.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  11. #11
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,090
    Rep Power
    6

    Default Re: error in prog to display floyds triangle

    Quote Originally Posted by JosAH View Post
    A phone is for making phone calls
    Indeed. But nowadays there are SMART phones. They are not for making phone calls, it is a replacement brain. The phone is your memory, your problem solver, your navigator, your personality.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  12. #12
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,651
    Blog Entries
    7
    Rep Power
    21

    Default Re: error in prog to display floyds triangle

    Quote Originally Posted by gimbal2 View Post
    Indeed. But nowadays there are SMART phones. They are not for making phone calls, it is a replacement brain. The phone is your memory, your problem solver, your navigator, your personality.
    For me it's my fridge; it's my guardian angel because it takes care of my Grolsch beer. No phone can do that.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  13. #13
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,091
    Rep Power
    20

    Default Re: error in prog to display floyds triangle

    Quote Originally Posted by JosAH View Post
    For me it's my fridge; it's my guardian angel because it takes care of my Grolsch beer. No phone can do that.

    kind regards,

    Jos
    Fridge phone.

    You'd need quite a large pocket, though...

    (OK, it's a sticker).
    Abbhirami likes this.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  14. #14
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,651
    Blog Entries
    7
    Rep Power
    21

    Default Re: error in prog to display floyds triangle

    Quote Originally Posted by Tolls View Post
    Fridge phone.

    You'd need quite a large pocket, though...

    (OK, it's a sticker).
    That is almost as cool as a http://www.amazon.ca/s/?ie=UTF8&keywords=usb+fridge&tag=googcana-20&index=aps&hvadid=34017095622&hvpos=1t2&hvexid=& hvnetw=g&hvrand=10216833057049237060&hvpone=&hvptw o=&hvqmt=e&hvdev=c&ref=pd_sl_meq4x39eh_e (very handy for my Grolsch supply on the job ;-)

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  15. #15
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,090
    Rep Power
    6

    Default Re: error in prog to display floyds triangle

    Okay now I'm curious: why specifically Amazon Canada? They don't sell it anywhere else? Or that was just the first Google hit ;)
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  16. #16
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,651
    Blog Entries
    7
    Rep Power
    21

    Default Re: error in prog to display floyds triangle

    Quote Originally Posted by gimbal2 View Post
    Okay now I'm curious: why specifically Amazon Canada? They don't sell it anywhere else? Or that was just the first Google hit ;)
    What's wrong with Canada? I obtain my tobacco from Belgium and my components from Germany, so why not Canada?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  17. #17
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,090
    Rep Power
    6

    Default Re: error in prog to display floyds triangle

    Such an evasive answer. You're secretly a Canadian pretending to be in the Netherlands aren't you?

    (there is nothing wrong with Canada, if I ever move to another country it is at the top of my list of choices).
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. error in ascending order prog of java
    By simar in forum New To Java
    Replies: 3
    Last Post: 08-10-2014, 06:30 PM
  2. error in java prog "end of file while parsing
    By simar in forum New To Java
    Replies: 4
    Last Post: 08-09-2014, 08:49 PM
  3. Error in inverted Pascal triangle program
    By darkwolf1345 in forum New To Java
    Replies: 3
    Last Post: 11-15-2012, 07:28 PM
  4. Error in Hibernate prog
    By Keerthi in forum Eclipse
    Replies: 6
    Last Post: 10-27-2009, 07:20 PM
  5. Replies: 1
    Last Post: 07-13-2008, 03:16 PM

Posting Permissions

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