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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:05:18+00:00 2026-05-27T19:05:18+00:00

Given: int x = 10; double d = -3.0; boolean f = false; 1.

  • 0

Given:

int x = 10;
double d = -3.0;
boolean f = false;

1.

Why does the following remain a double after it is cast as an int… For the second one also, why does it output a float when defined as a long?:

(int) d / 2.0
(long) d * 2f

2.

Why does the first of the following print a string(?), and the latter a number?

"2" + x + 2
"3" + 3 * x

But then there is an error with the following:

"5" + i + 2

3.

Also, with the follwing, what is actually happening and what is the result?

d++ + d

4.

When Math.round is used, why does it convert the following double into a float, or are they the same thing?

Math.round(x / d)
  • 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-27T19:05:19+00:00Added an answer on May 27, 2026 at 7:05 pm

    Why does the following remain a double after it is cast as an int… For the second one also, why does it output a float when defined as a long?:

    (int) d / 2.0
    (long) d * 2f
    

    Because priority of cast (int) operator is higher that / and * operators.
    You should read it like this:

    ((int) d) / 2.0
    
    ((long) d) * 2f
    

    Why does the first of the following print a string(?), and the latter a number?

    "2" + x + 2
    "3" + 3 * x
    

    I think it’s string in both casesm you must “read” this expressions like this:

    ("2" + x) + 2
    "3" + (3 * x)
    

    But then there is an error with the following:

    "5" + i + 2
    

    What is the error?

    Also, with the follwing, what is actually happening and what is the result?

    d++ + d
    

    This is a sequence of actions:

    1. tmp = d
    2. d = d + 1
    3. return tmp + d

    When Math.round is used, why does it convert the following double into a float, or are they the same thing?

    Math.round(x / d)
    

    It converts to long, because return type of Math.round(double) is long

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

Sidebar

Related Questions

Consider the following setup: I am given an interface template<class T> void FooClass<T>::foo(boost::function<double (int)>
Given int a; , I know that the following returns the largest value that
Given the following code: int *a = NULL; a = calloc(1, sizeof(*a)); printf(%d\n, a);
Given the following: declare @a table ( pkid int, value int ) declare @b
Given the following class public class Foo { public int FooId { get; set;
For a given int sequence check number of double palindromes, where by double palindrome
Given: case class Foo(a: Int, b: String, c: Double) you can say: val params
Given an assembly with an entry point like: int FooClass::doFoo(int x, double y) {
Given: unsigned int a, b, c, d; I want: d = a * b
i have been given class with int variables x and y in private, and

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.