Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: syntax error in if else condition

  1. #1
    Junior Member
    Join Date
    Dec 2017
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default syntax error in if else condition

    Dear Java users,
    I don't have computer science background but I have knowledge about programs and have been using the MatLAB for on and off project. I have knowledge about the loops and conditions basics but not familiar with the syntax errors in java.
    Trying to write a simple program using if, else if condition and it gives error on line 18 please check below:

    I will appreciate your help!

    import java.util.Scanner;

    public class PracticeIfStatement {
    public static void main(String[] args) {


    Scanner input = new Scanner(System.in);


    try {

    System.out.println("Enter your age:");
    int age = input.nextInt();

    if (age > 0 && age <=10 );{
    System.out.println("Your age is from 0 to 10");
    }
    //18th line (error syntax error on token)
    else if (age >=11 && age <=20){
    System.out.println("your age is from 11 to 20");
    }

    else if ( age >=20 && age <=30) {
    System.out.println("your age is from 20 to 30");
    }

    else {
    System.out.println("Your are above 30");
    }
    }
    catch(Exception e) {
    System.out.println("You can not enter Zero");
    }

    }
    }

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,399
    Thanks
    53
    Thanked 2,399 Times in 2,352 Posts

    Default Re: syntax error in if else condition

    it gives error on line 18
    Which is line 18?

    Please copy the full text of the error message and paste it here. It has important info about the error.


    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. syntax error
    By juliaannn in forum What's Wrong With My Code?
    Replies: 2
    Last Post: August 1st, 2014, 03:40 AM
  2. LSP: weaken pre-condition and strengthen post-condition
    By Capital in forum Object Oriented Programming
    Replies: 1
    Last Post: July 13th, 2014, 12:46 PM
  3. Syntax error!!!
    By Gerock7 in forum What's Wrong With My Code?
    Replies: 23
    Last Post: April 22nd, 2014, 07:14 PM
  4. Syntax error
    By Kez in forum What's Wrong With My Code?
    Replies: 1
    Last Post: January 19th, 2014, 03:48 PM
  5. Syntax error with dispose()
    By jagnat in forum AWT / Java Swing
    Replies: 1
    Last Post: October 14th, 2011, 11:00 AM

Tags for this Thread