Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6153951
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:10:46+00:00 2026-05-23T20:10:46+00:00

Well been working for hours today so i might be missing something silly, but,

  • 0

Well been working for hours today so i might be missing something silly, but, at this point I’m kinda blind with this and looking for an explanation for this behaviour

i made an example of the problem I’m having and the solution i found is not quite a solution.

The Problem: to the following function I pass 1 as shotCount and 9 as Countdown
the result when i debug, i see the first if run, and run the return 2, but then also the else decides to run to and finally return -1

    public int getNextShot(int shotCount, int Countdown)
    {
        if ((shotCount == 1) && (Countdown != 10)) return 2;
        else if (shotCount == 0) return 1;
        else return -1;
    }

BUT if i do this (same parameters) it works:

   public int getNextShot(int shotCount, int Countdown)
    {
        int res = -2;
        if ((shotCount == 1) && (Countdown != 10))  res = 2;
        else if (shotCount == 0) res = 1;
        else res = -1;
        return res;
    }

Am I missing something here?

Thanks 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T20:10:47+00:00Added an answer on May 23, 2026 at 8:10 pm

    I think you are mistaken.

    Sometimes the debugger in Eclipse acts like its jumping to the last line of the method call but then does return the correct value.

    For example, I just copied and pasted your code and it ran fine for me. The below code prints 2.

    public class AA {
    
            public static void main(String[] args) {
    
                    System.out.println(getNextShot(1, 9));
    
            }
    
            public static int getNextShot(int shotCount, int Countdown)
        {
            if ((shotCount == 1) && (Countdown != 10)) return 2;
            else if (shotCount == 0) return 1;
            else return -1;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We use Apache as a reverse proxy server. This has been working well, but
My IDE has been working very well, until today. When I try to compile
I've been working on this problem for 7 hours now, and I still have
I've been working on this for about 5 hours for homework and I was
this may well be a very basic question, but I haven't been able to
An application that has been working well for months has stopped picking up the
I'm working on my first PHP project, and it's going well. I've been able
Well I was going to ask what the difference is but it's been answered
We've been using Trac for task/defect tracking and things were going well enough, but
Well, I guess this day had to come. My client's website has been compromised

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.