一个小的java程序 [英] a small java program
问题描述
两个变量的总和,不使用数学运算符。
sum of two varaibles without using mathematical operators.
推荐答案
两个变量的总和,不使用数学运算符。
sum of two varaibles without using mathematical operators.
这是一个测验问题吗?我能赢得什么?
亲切的问候,
Jos
Is this a quiz question? What can I win?
kind regards,
Jos
两个变量的总和,不使用数学运算符。
sum of two varaibles without using mathematical operators.
如果两个变量的类型为float或double,则必须在不使用算术运算符的情况下实现符合IEEE-754的加法。它可能已经完成,但结果代码肯定不会是一个小的Java程序。
因此,如果问题是:如何制作一个小型java程序,在不使用算术运算符的情况下计算两个变量的总和?,我的答案是:它不可能完成
那么我赢了什么? :)
if the two variables are of type float or double, you would have to implement IEEE-754-conforming addition without using arithmetic operators. It could probably be done, but the resulting code would certainly not be "a small java program".
So if the question is: "How do you make a small java program that calculates the sum of two variables without using arithmetic operators?", my answer is: "It can''t be done"
So what do I win? :)
如果两个变量的类型为float或double,则必须在不使用算术的情况下实现符合IEEE-754的加法运营商。它可能已经完成,但结果代码肯定不会是一个小的Java程序。
因此,如果问题是:如何制作一个小型java程序,在不使用算术运算符的情况下计算两个变量的总和?,我的答案是:它不可能完成
那么我赢了什么? :)
if the two variables are of type float or double, you would have to implement IEEE-754-conforming addition without using arithmetic operators. It could probably be done, but the resulting code would certainly not be "a small java program".
So if the question is: "How do you make a small java program that calculates the sum of two variables without using arithmetic operators?", my answer is: "It can''t be done"
So what do I win? :)
小是一个相对术语...加法器不是太复杂(三位输入,两个变量你要求和并且输入进位,两位输出,进位和和位)然后我们只需要将变量转换为它们的二进制补码字节,这很容易,因为java只存储有符号值。
注意:当你使用'+''符号时,你的电脑会这样做。
任何原语都没有区别type(float,double,integer,long,short)。只要你的转换为字节码即可。方法正常工作你应该完全没问题。
-blazed
Small is a relative term... an adder isn''t tall too complicated (three-bit input, two variables you''re going to sum and the input carry bit, two-bit output, carry bit and sum bit) and then we just need to convert the variables to their two''s-compliment byte equivalents and that''s easy enough since java already stores only signed values.
Note: your computer does this when you use the ''+'' sign anyway.
There would be no difference between any primitive type (float, double, integer, long, short). So long as your "convert-to-bytecode" methods work correctly you should be perfectly fine.
-blazed
这篇关于一个小的java程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!