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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:03:03+00:00 2026-06-12T10:03:03+00:00

Can someone explain how typecasting works in the line int y = (int) x;

  • 0

Can someone explain how typecasting works in the line int y = (int) x;
Thank You

public class typecast
{
 public static void main(String [] args)
 {
  double x=10.5;
  int y=(int) x;
  System.out.println("x="+x);
  System.out.println("y="+y);
 } 
}
  • 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-12T10:03:04+00:00Added an answer on June 12, 2026 at 10:03 am

    The type cast performs a narrowing type conversion. The exact conversion depends on the double value, as follows:

    • If it is within the range of int values, it is rounded towards zero.
    • If it outside of the range or is an “Inf” value, then the conversion gives Integer.MIN_VALUE or Integer.MAX_VALUE, depending on the sign.
    • If it is a “NaN” value, the conversion gives zero.

    Reference: JLS 5.1.3

    Note: “round towards zero” is defined as follows:

    “The Java programming language uses round toward zero when converting a floating value to an integer (§5.1.3), which acts, in this case, as though the number were truncated, discarding the mantissa bits. Rounding toward zero chooses at its result the format’s value closest to and no greater in magnitude than the infinitely precise result.“

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

Sidebar

Related Questions

Can someone explain to me why this line works: conn = DriverManager.getConnection(jdbc:mysql://myWebsite.com:3306/schemaName?user=userX&password=passwordX); But this
Can someone explain to me why the following code does not work? public class
Can someone explain me why this works: select val1, val2, count(case when table2.someID in
Can someone explain how the organisation of classes in Pharo works in different versions
Can someone explain why unsigned int is taking a negative value? An unsigned int
Can someone explain why, when a query should be returning one string item only
Can someone explain me how to overcome this thing? String.prototype.one = 1; one.one; //returns
Can someone explain how users accounts works on webpage? www.website.com/profile? uid=15636373282 or www.website.com/profile/ 15636373282
Can someone explain clearly why this implementation (from SO 3965054) of min_of_list works in
Can someone explain why this code doesn't work? Intent i = new Intent(this.context, SomeClass.class);

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.