开发者

What is the answer of: 6÷2(1+2) =?

I have this debate, whether the answer of 6÷2(1+2) is 9 or 1.

public class bodmas
{
public static void main(String [] args)
{
    float i = 6/2*(1+2);
    System.out.println(i);
}

}

Java returns 9, but that's because I cannot remove the * sign. If I put this into my Casio fx-82MS calculator it returns 9 if I insert 6/2*(1+2) but 1 if I insert 6/2(1+2)

This worries me as a Java Developer because if the answer is really different, we have a problem. I have tried it on different versions of calculators, the answer gives out 9, however on mine it gives out 1. So probably there's nothing to worry about.

开发者_JAVA百科

As a Conclusion, the question is ambiguous and in programming terms it would return 9. If it had to return 1, a more clear question would be 6/(2*(1+2)) .


According to Order of Operations the answer should be 9.


It depends on how you define your representation. In Java (indeed, in most languages):

6 / 2 * (1+2)

is equivalent to

(6 / 2) * (1+2)

which is 9.

Your calculator is interpreting it as:

6 / (2 * (1+2))

which is indeed 1.


I am amused by the com "9 is super wrong, you just break the laws of algebra" while they themselves forget that the parentheses are done first


omg guys. Ask youself: What is a ÷ a = ? It is ONE. Now think of Itentity Law: a = 1a = 1(a) now ask what is a ÷ 1a = ? Obviously 1 !! a ÷ 1a != a ÷ 1 * a What is a ÷ 2a ? Ans: 1/2 What is 6 ÷ 2a ? Ans: 3/a Let a = 1+2 in all of the above. Stop converting stuff like 2a = 2 * a. It is 2a = (2 * a)


the 9 answer is SUPER WRONG not only wrong. In math, the associative and commutative properties are laws applied to addition and multiplication that always exist..... meaning: 6÷2(2+1) must be equal to 6÷(2+1)2..... if we consider the convention used by the people who answered 9: 6÷2(2+1) = 9 6÷(2+1)2 = 4 This is wrong because multiplication is commutative and the convention should not break..... if we consider the convention used by the people who answered 1: 6÷2(2+1) = 1 6÷(2+1)2 = 1 this is consistent and correct......that's why the answer is 1.. its not about conventions its about basic abstract algebra..your interpretation of the expression is wrong because you are not preserving the laws of algebra. so 9 is SUPER WRONG not only wrong.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜