Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

'else' without 'if'

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello. I'm compiling my first program which
  • accepts 3 numbers from the user
  • sorts ascending
  • prints 3 numbers in ascending order


  • I am having a problem with my if/else statements
    ==============================
    "'else' without 'if'"
    ------------------------------
    else if (y > z); on line 28
    and
    else if (x > y); on line 33
    ------------------------------
    ==============================
    here is the code:

    This is my first program, so obviously I don't know exactly what I am doing. Any help would be appreciated.
    Thank you so much,
    JM
     
    Ranch Hand
    Posts: 265
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Remove the semi-colon from your if and else if statements. Here's the proper syntax for an if statement
     
    Ranch Hand
    Posts: 3061
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Also, you are missing the closing braces for the if block and for the else if block. Use the example above to see where the closing braces should go.
    Keep coding!
    Layne
     
    J Morberg
    Greenhorn
    Posts: 5
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Layne and Chad,
    Thank you both for your help. Your suggestions quickly fixed my problem.
    The code compiled w/out error...but now it wont execute!
    When trying to run my "Sort.class" file, I receive the following error:
    =================================
    Exception in thread "main" java.lang.NoClassDefFoundError: Sort
    =================================
    Hopefully this one is equally as simple to fix!
    Thanks again ~ JM
     
    Ranch Hand
    Posts: 67
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    the code runs fine for me..are u using the following command??
     
    J Morberg
    Greenhorn
    Posts: 5
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Rajeshwari,
    Thank you for checking the code out. Yes, I am using the right command.
    I believe I might have some classpath or something set up wrong. I am going to investigate that!

    I keep getting the error
    ------------------------------------
    Exception in thread "main" Java.lang.NoClassDefFoundError: Sort
    ------------------------------------
    my classpath is set to include the directory for my sdk installation; a QTJava.zip file residing in a j2rel.4.0 directory; and a servlet.jar file within a tomcat directory I've installed to run the server.
    As long as one of the classpath entries is set to the "j2sdk1.4.1_01" directory I should be fine, right?
    Does it seem that a missmatch in my classpath could create such a problem?
    Thanks.../JM
    ============
    oh, by the way...if it worked for you, then I feel much more confident that it's just a setting on my machine that is causing the problem. I will research and find out how to fix it. Thanks again for checking it!
    Take care/JM
     
    Rajeshwari Natarajan
    Ranch Hand
    Posts: 67
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    From which directory are u running the program?
    U shud be running the java class from the directory in which the .class file is created.
    If u are running from jdk1.4\bin or any other folder then the directory containing the class file must be included in the classpath.
    If sample is the name of the directory containing Sort.class then give the following command..

    and then run ur program.
     
    Consider Paul's rocket mass heater.
    reply
      Bookmark Topic Watch Topic
    • New Topic