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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:26:50+00:00 2026-06-14T20:26:50+00:00

I have a question, In Java , does Math.min bind tighter than ++ ?

  • 0

I have a question,
In Java, does Math.min bind tighter than ++?
Let me illustrate with an example and maybe someone can explain to me why I get the results I get.

Here’s a method I run:

private static void testIncrement() {
    int x=10;
    System.out.println(x++);
    System.out.println(x);

    x=10;
    System.out.println("-----------");
    System.out.println(++x);
    System.out.println(x);

    x=10;
    System.out.println("-----------\n"+x); //10
    x=Math.min(255, x++); 
    System.out.println(x); **//x=10 WHY NOT x=11?**

    x=10;
    System.out.println("-----------\n"+x);
    x=Math.min(255, ++x);
    System.out.println(x);
}

The results are:

10
11
-----------
11
11
-----------
10
10
-----------
10
11

On the line where I put //x=10 WHY NOT x=11?
I wonder why x is 10 and not 11. Maybe someone can explain this to me.

It looks as if Math.min create a copy of x (which is 10 at this time) which it uses to do Math.min. Then the original x is incremented from 10 to 11, but the copy which is still 10 comes out of Math.min and overwrites the incremented one.

Does this make sense?
Does anyone have an explanation for why x is 10 and not 11 in this case?

Thanks

PS – I totally understand How do the post increment (i++) and pre increment (++i) operators work in Java?

  • 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-14T20:26:51+00:00Added an answer on June 14, 2026 at 8:26 pm

    Let’s deconstruct this line:

    x = Math.min(255, x++); 
    

    The x++ means “remember the original value of x; then increment x; then the value of the expression is the original value”. All of this happens before the assignment. So it’s equivalent to:

    int tmp = x;               // x = 10, tmp = 10
    x = x + 1;                 // x = 11, tmp = 10
    x = Math.min(255, tmp);    // x = 10
    

    Hopefully that should make it clear. In particular, this has nothing to do with Math.min itself – it’s just behaving as a normal method invocation. See section 15.14.2 of the JLS for more details.

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

Sidebar

Related Questions

Question:- Does java client need to worry about multiple servers ? Meaning:- I have
Java 6 API question. Does calling LockSupport.unpark(thread) have a happens-before relationship to the return
I have some question over here regarding the java garbage collector. First let me
The question but in C#. So does Java have C#'s command? I need it
I have a more complicated issue (than question 'Java map with values limited by
This maybe a related question: Java assignment issues - Is this atomic? I have
Dear all,Now i have this question in my java program,I think it should be
I have a question about how GC works in Java. Consider the following code:
I have a question about best practices in Java. I'm writing a class, which
I have a question regarding the iterator behavior in Java. I have a call

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.