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

  • Home
  • SEARCH
  • 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 6090905
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:16:01+00:00 2026-05-23T12:16:01+00:00

I´m new to programming, and are doing som exercices. In this exercice I am

  • 0

I´m new to programming, and are doing som exercices. In this exercice I am supposed to write a program that reads in three numbers from the user of the program. The program is supposed to find the smallest number, and print which one is the smallest number.
Here is my code:

import javax.swing.JOptionPane;

public class Smallestnumber
{
  public static void main( String args[] )
    {
    // Defining variables:
    String firstnumberstring;
    String secondnumberstring;
    String thirdnumberstring;
    String result;
    int firstnumber;
    int secondnumber;
    int thirdnumber;

    // Making input frames:
    firstnumberstring = JOptionPane.showInputDialog( "Write first number!" );
    secondnumberstring = JOptionPane.showInputDialog( "Write second number!");
    thirdnumberstring = JOptionPane.showInputDialog( "Write third number!" );

    // Converting stringvalues to int values:
    firstnumber = Integer.parseInt( firstnumberstring );
    secondnumber = Integer.parseInt( secondnumberstring );
    thirdnumber = Integer.parseInt( thirdnumberstring );

    // Initialising printstring to an empty string:
    result = "";

    if ( firstnumber < secondnumber < thirdnumber )
    result = firstnumber + " is the smallest number!";

    if ( firstnumber < thirdnumber < secondnumber )
    result = firstnumber + " is the smallest number!";

    if ( secondnumber < firstnumber < thirdnumber )
    result = secondnumber + " is the smallest number!";

    if ( secondnumber < thirdnumber < firstnumber )
    result = secondnumber + " is the smallest number!";

    if ( thirdnumber < firstnumber < secondnumber )
    result = thirdnumber + " is the smallest number!";

    if ( thirdnumber < secondnumber < firstnumber )
    result = thirdnumber + " is the smallest number!";

    // Making conclusion box:
    JOptionPane.showMessageDialog( null, result, "Conclusion:", JOptionPane.INFORMATION_MESSAGE );

    } // End of main method
} // End of class Smallestnumber

And here is the error messages:

Smallestnumber.java:29: operator < cannot be applied to boolean,int
    if ( firstnumber < secondnumber < thirdnumber )
                                    ^
Smallestnumber.java:32: operator < cannot be applied to boolean,int
    if ( firstnumber < thirdnumber < secondnumber )
                                   ^
Smallestnumber.java:35: operator < cannot be applied to boolean,int
    if ( secondnumber < firstnumber < thirdnumber )
                                    ^
Smallestnumber.java:38: operator < cannot be applied to boolean,int
    if ( secondnumber < thirdnumber < firstnumber )
                                    ^
Smallestnumber.java:41: operator < cannot be applied to boolean,int
    if ( thirdnumber < firstnumber < secondnumber )
                                   ^
Smallestnumber.java:44: operator < cannot be applied to boolean,int
    if ( thirdnumber < secondnumber < firstnumber )
                                    ^
6 errors

How can I get the program to work?

  • 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-23T12:16:02+00:00Added an answer on May 23, 2026 at 12:16 pm

    You can’t do thirdnumber < secondnumber < firstnumber in Java, as it interprets it as (thirdnumber < secondnumber) < firstnumber, comparing true or false to the number.

    What you want is to combine two conditions like this:

    if ( firstnumber < secondnumber && secondnumber < thirdnumber )
    result = firstnumber + " is the smallest number!";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am fairly new to programming and while doing a lot of reading this
I'm new to web programming and doing different tutorials that I can find on
I'm very much new to programming and have been doing fairly well so far.
let's say that you in your new programming work your boss comes and says
I always believed that when starting to learn a new programming language programmer must
I've came across this new acronym, SOFEA, apparently a new programming paradigm for web
I am very new to programming, so I apologize if this question seems absurdly
I'm new at programming, new on this site too, so hello... I'm attempting to
I am quite new at database programming and I am having trouble doing searches
I am quite new at database programming and I am having trouble doing searches

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.