Page 2 of 2 FirstFirst 12
Results 21 to 27 of 27

Thread: Java Program

  1. #21
    icedragon770 is offline Member
    Join Date
    Oct 2008
    Posts
    36
    Rep Power
    0

    Default Error on java dont know what i did wrong

    it said error on else without if
    int largest; // Largest of the three values.
    int smallest; // Smallest of the three values.
    int x;
    int y;
    int z;
    //Write assignment, if, or if else statements here as appropriate.

    if (x>y)
    largest=x;
    smallest=y;
    else
    largest=y;
    smallest=x;
    if (largest<z)
    largest=z;
    if (smallest>z)
    smallest=z;
    thats how it look whats wrong?

  2. #22
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,242
    Rep Power
    19

    Default

    What's wrong is that you posted your code without using the code tags, and that you didn't use braces { } to surround the if / else blocks.

    db

  3. #23
    DevzAbhi's Avatar
    DevzAbhi is offline Member
    Join Date
    Jul 2008
    Posts
    67
    Rep Power
    0

    Default

    int largest; // Largest of the three values.
    int smallest; // Smallest of the three values.
    int x;
    int y;
    int z;
    //Write assignment, if, or if else statements here as appropriate.

    if (x>y){
    largest=x;
    smallest=y;

    }
    else
    {largest=y;
    smallest=x;
    }
    if (largest<z)
    {
    largest=z;
    }

    if (smallest>z)
    {
    smallest=z;
    }



    Always use braces for enclosing the block of code .{}

  4. #24
    icedragon770 is offline Member
    Join Date
    Oct 2008
    Posts
    36
    Rep Power
    0

    Default

    Quote Originally Posted by DevzAbhi View Post
    int largest; // Largest of the three values.
    int smallest; // Smallest of the three values.
    int x;
    int y;
    int z;
    //Write assignment, if, or if else statements here as appropriate.

    if (x>y){
    largest=x;
    smallest=y;

    }
    else
    {largest=y;
    smallest=x;
    }
    if (largest<z)
    {
    largest=z;
    }

    if (smallest>z)
    {
    smallest=z;
    }



    Always use braces for enclosing the block of code .{}
    that helps a lot

  5. #25
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,423
    Rep Power
    25

    Default

    {largest=y;
    I'd recommend NOT putting code on the same line as the {
    When you go to add code often it will between the { and the first line of code.
    And a standing alone { is easier to see than one next to a statement

  6. #26
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,242
    Rep Power
    19

    Default

    What Norm said, plus a whole lot more valuable stuff:
    Code Conventions for the Java(TM) Programming Language: Contents

    db

  7. #27
    icedragon770 is offline Member
    Join Date
    Oct 2008
    Posts
    36
    Rep Power
    0

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Replies: 0
    Last Post: 04-04-2008, 02:40 PM
  2. New to Java Program
    By jvasilj1 in forum New To Java
    Replies: 1
    Last Post: 02-05-2008, 07:22 AM
  3. Replies: 0
    Last Post: 10-04-2007, 09:33 PM
  4. help with java program
    By mattvgt in forum New To Java
    Replies: 3
    Last Post: 07-14-2007, 04:57 PM
  5. java program
    By nehasahu in forum New To Java
    Replies: 5
    Last Post: 07-12-2007, 11:05 AM

Posting Permissions

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