Ask your own question, for FREE!
Computer Science 7 Online
OpenStudy (anonymous):

how to write x = 1/2(xn +5/xn) in java

OpenStudy (lyrae):

I'm not really sure about that expression, do you mind clarifying it a bit? However, here's my interpretation: class TestClass { public static void main (String[] args) { /* Interpretation of: x = (x1*n1 + 5/(x1*n1))/2; */ int x1 = 2, // Some test-values n1 = 2; x1 = (x1*n1 + 5/(x1*n1))/2; System.out.println("X as an integear: "+ x1); double x2 = 2, // Some test-values n2 = 2; x2 = (x2*n2 + 5.0/(x2*n2))/2.0; System.out.println("X as a double: "+ x2); } } Runnable example: https://ideone.com/Sb2Lkl

OpenStudy (kainui):

I would just suggest using more parenthesis.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!