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.


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

Results 1 to 2 of 2

Thread: unreachable statement?

  1. #1
    Java kindergarten chronoz13's Avatar
    Join Date
    Mar 2009
    Thanked 30 Times in 28 Posts

    Default unreachable statement?

    public class Sample {
        private static final int MIN_NUMBER = 5;
        private int number;
        public int set(double num) {
            number = (int) num;
            if (minimumNumber()) {
                return number - number;
            else {
                System.out.println("LARGET THAN THE MINIMUM NUMBER!");
                return number + 10000;
            if ( number == 10000) {
                System.out.println("SO LARGE");
            return number + 100;
        public boolean minimumNumber() {
                return number <= MIN_NUMBER;

    having some errors here

  2. #2
    Super Moderator Json's Avatar
    Join Date
    Jul 2009
    Warrington, United Kingdom
    My Mood
    Thanked 156 Times in 152 Posts

    Default Re: unreachable statement?

    In your set method this code will never be reached.

            if ( number == 10000) {
                System.out.println("SO LARGE");
            return number + 100;

    This is because the if statement above it will either return something if it is true and if it isn't it will also return something. Therefore your method will have returned something before reaching the mentioned code.

    // Json

Similar Threads

  1. How to Use the Java switch statement
    By JavaPF in forum Java Programming Tutorials
    Replies: 6
    Last Post: April 18th, 2013, 05:19 PM
  2. Prime number generator program missing return statement
    By 03EVOAWD in forum What's Wrong With My Code?
    Replies: 13
    Last Post: September 10th, 2009, 09:17 AM
  3. If statement
    By Dave in forum Loops & Control Statements
    Replies: 2
    Last Post: August 27th, 2009, 10:11 AM
  4. Error of "Class has no return statement"
    By mdstrauss in forum What's Wrong With My Code?
    Replies: 7
    Last Post: August 2nd, 2009, 12:00 PM
  5. [SOLVED] Switch statement question
    By shikh_albelad in forum Loops & Control Statements
    Replies: 5
    Last Post: May 31st, 2009, 05:13 AM