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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T22:01:48+00:00 2026-05-30T22:01:48+00:00

The user enters 3 numbers and I’m assuming all are proper integers and distinct.

  • 0

The user enters 3 numbers and I’m assuming all are proper integers and distinct. I’m trying to get the program to print out a sequence starting from the number of the lowest value to the highest value. Why doesn’t my else if work here? Or am I making some glaring mistake in the code?

The code is not complete, I’ve only written this far and then tested it. When I input 8 then 2 and then 4, I intend it to print out 2,3,4,5,6,7,8, but it doesn’t. Instead it prints out 4,5,6,7,8,

    System.out.print("Enter a number: ");
    int n1 = Integer.parseInt(in.readLine());
    System.out.print("Enter a number: ");
    int n2 = Integer.parseInt(in.readLine());
    System.out.print("Enter a number: ");
    int n3 = Integer.parseInt(in.readLine());

    if ((n1 > n2) | (n2 > n3)) {
        for (int i = n3; (i <= n1); i++) {
            System.out.print(i + ",");
        }
    }
    else if ((n1 > n3) | (n3 > n2)) {
        for (int i = n2; (i <= n1); i++) {
            System.out.print(i + ",");
        }
    }
    }
}
  • 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-30T22:01:49+00:00Added an answer on May 30, 2026 at 10:01 pm

    Presumably, in your first condition, you want to say “n1 is greater than n2, and n2 is greater than n3”. However, the “and” operator is written as &&, not as | (which is a bit-level “or” operator). Thus, your first condition (n1 > n2) is sufficient to satisfy the first if, so else doesn’t apply.

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

Sidebar

Related Questions

this is what i'm trying to do: User enters numbers into the program and
I'm trying to build a program that goes like this: User enters 3 numbers.
I am trying to create a program where a user enters four numbers using
I'm trying to write a small program that prints out distinct numbers in an
I have a program where a user enters a list of numbers in the
I have a simple application that has richTextBox and button. User enters numbers(integers) into
If a user enters 5 numbers, lets say... 4, 4, 7, 7, 4 .
How do I check and see if a user enters only numbers and is
I have 'n' numbers in a TEXTAREA on a form. After the user enters
My program reads a list of integers from user input [ keyboard] and calculates

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.