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 8013169
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T19:33:43+00:00 2026-06-04T19:33:43+00:00

My if statement doesnt seem to be working, whatever I put in always seems

  • 0

My “if” statement doesnt seem to be working, whatever I put in always seems to default to my “else” statement. Such as if I put in the integer “1” or “2”, which have “if” statements associated with them, it still defaults to “else”. Any help would be appreciated 🙂

String number = JOptionPane.showInputDialog("Would you like a custom loop count or an infinite? 1.  Custom   2. Infinite"); //test choice
n = Integer.parseInt(number);
while (n < 0 || n > 2) {
    if (n == 1) {


        String number2 = JOptionPane.showInputDialog("How many times would you like to loop?");
        integer = Integer.parseInt(number2);
        while (integer < 0) {
            while (x < integer) {
                g.drawString("hi", 200, y);

                x += 1;
                y = y + 40; //test
            }//end while
        }
    }//end if 
    else if (n == 2) {
        while (1 == 1);
    }//end if   
    else;
}
g.drawString("Please pick a valid choice", 200, 200);
  • 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-06-04T19:33:46+00:00Added an answer on June 4, 2026 at 7:33 pm

    If the block after

    while (n<0 || n>2)
    

    is executed, you know that n is either < 0 or > 2. Therefore it can’t be equal to 1 or 2 and the else block is executed, which happens to be empty because it is followed by a ;.

    That’s not mentioning the few weird statements found in your code 😉

    ps: I have edited your post to add proper indentation to your code and include { and }. It might look a little clearer now.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following statement and the IF ELSE doesn't seem to be working?
I'm kind of stuck on something... my else statement doesn't seem to be working
Im working with a large dataset of point of interest (POI) which all have
I have created a loop, inside there is an if statment but it doesnt
I'm trying to write an IF ELSE statement to enable shipping, If user doesn't
Problem Statement is somewhat like this: Given a website, we have to classify it
Problem statement: For a given positive number, I have to find out the immediately
I'm learning mysql and have been trying to get this working, but an error
I have got this half working but, when I try and create an if
Ok so I'm working on a larger SQL statement, but I've come across an

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.