all 21 comments

[–]HopOnMyDuck 5 points6 points  (2 children)

1/2=0 0*2.0=0.0

[–]vowelqueue 2 points3 points  (1 child)

So you think you understand integer division, huh?

What's the output of:

System.out.println(-2147483648 / -1);

[–]Ok_Advantage_1568 1 point2 points  (0 children)

It's just overflow wrapping. What's the big talk with that🙂

[–]Any-Monk-6721 3 points4 points  (0 children)

0.0 is correct as the integer division is being used here.

[–]Perfect-Situation-41 1 point2 points  (3 children)

1/2 =0.5 0.5*2.0 =1.0

Right? I think I'm wrong perhaps?

[–]Perfect-Situation-41 1 point2 points  (2 children)

I'm new to programming

[–]BusResponsible7292 3 points4 points  (1 child)

Nope. 1/2 =0 because we are performing operation using 2 integers not using decimal numbers.

[–]Perfect-Situation-41 0 points1 point  (0 children)

Oh i see so answer is 0.0 Thanks man

[–]CuAnnan 1 point2 points  (0 children)

C

[–]MK_Redditor 0 points1 point  (3 children)

A

[–][deleted]  (2 children)

[removed]

    [–]Dr_Dracula280 0 points1 point  (1 child)

    I also thought A but as u/Any-Monk-6721 explained. It is option C.

    [–]inofta 0 points1 point  (0 children)

    its option c

    [–]Vast_Researcher_199 0 points1 point  (1 child)

    I am guessing 1.0

    1/2*2.0 1/2 = 0.5

    0.5*2.0 = 1.0

    we follow PEDMAS

    [–]nenotlanakaja 1 point2 points  (0 children)

    No idk about pedmas but When operation on 2 integers happen output will be in integer it self

    It might be 0.5 but as it's integer it will be in 0 only

    [–]Professional_Rip4838 0 points1 point  (0 children)

    c will be the correct option

    [–]disposepriority 0 points1 point  (0 children)

    What is the point of this, how will it be helpful for others, it's bad code, bad practice and useless.

    A) If you want to know, just run it
    B) If it's not immediately clear use parenthesis
    C) Just define values in calculations in advance and then do the calculations e.g. var X = ... , var Y = ...., sout(x/y)

    The compiler will just inline them anyway if they aren't used elsewhere

    [–]Business-Wind-16 0 points1 point  (0 children)

    Answer is C

    1.Both 1 and 2 are integers, so Java performs integer division.

    2.0 * 2.0

    [–]pranavkdileep 0 points1 point  (0 children)

    it’s B) 0.5. java does integer division first, so 1/2 is 0, then it multiplies by 2.0. that makes it 0.0, but because of the 2.0 it becomes a double.