In Java, losing accuracy while applying math functions [closed] - java

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
I am getting wrong output while using java Math functions.
expected output = 4.32
present output= 4.30287105016515
double startHeight= 60.00;
double initaldistance=1000.00;
double speed=120;
startDistance=(initaldistance-1.688*speed);
startAngle = Math.toDegrees(Math.atan(startHeight/startDistance));
System.out.println(startAngle);

Your expected output is incorrect. The arithmetic expressed in the code in the question does indeed have a result near 4.30287.

Related

How can we implement initial capacity and load factor for Hashtable in our code [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
When i use the below code it is throwing me error
Hashtable htl = new Hashtable(int 50, float 0.90);
Error: Syntax error on token "int", delete this token
You don't place the types when calling a method.
Just replace with
Hashtable htl=new Hashtable(50, 0.90);

Calculating Averages for an ArrayList in Java [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I've been trying to calculate averages for parameters stored in ArrayList but always seem to receive 0 when calling my numberAverage class after adding new int objects to the ArrayList and I could really do with some help to point me in the right direction.
Thank you.
You did the reverse of what mean actually is. Use this:
double mean = ((double)aggregate / numberAverage.size());

Why is this Java long overflowing? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
This is very weird.
A class I wrote has the following data member:
final static long MAX_FILE_SIZE_BYTES = 50000000000L;
at one point in my code the following block is run
System.out.println("MAXFILESIZEBYTES: " + MAX_FILE_SIZE_BYTES);
and the output is:
MAXFILESIZEBYTES: -1539607552
My question is, why is this long value overflowing? Java is supposed to be machine independent, and longs are supposed to hold 64 bits. What gives?
Cannot reproduce.
50000000000L is 0x0000000BA43B7400.
-1539607552 is FFFFFFFFA43B7400, which is what you would get if you cast the value to int.
Ergo somewhere you are casting it to int. Maybe you have a shadowed variable.

How to subtract a number(int) from a character in java [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
Hi I'm trying to subtract an int from a char but I keep being told that the compiler "cannot convert from int to char".
I have tried changing the constant to a char but it didn't help.
is there any easy way to do this subtraction?
test[1] = characterArray[1] - ASCII_SUB;
Any help much would be appreciated.
The problem is that subtraction is never performed on char values in Java. Instead, both operands are promoted to int (via binary numeric promotion), and the result of the subtraction is an int as well. So you'll need to cast the result back to char:
test[1] = (char) (characterArray[1] - ASCII_SUB);

asin() not working properly in Java [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
If I try to get the sin and sin-1 of 0.5 degree, I get virtually the same answer.
sin-1(0.5) should have been 30.
Log.d("XYZ", Math.sin(Math.toRadians(0.5)) +"___"+ Math.asin(Math.toRadians(0.5)));
Result: 0.008726535498373935___0.008726757025787037
Any idea what I am doing wrong?
One of the part of your code i.e. Math.asin(Math.toRadians(0.5)) is wrong....
0.5 is a numerical value you don't need to change it to Radians the correct one is.
Log.d("XYZ", Math.sin(Math.toRadians(0.5)) +"___"+ Math.toDegrees(Math.asin(0.5));
the function "Math.asin(0.5)" give value in radians so you need to convert it to degrees.
and it is not "sin-1 of 0.5 degrees" rather it is" sin-1 of 0.5" ..."degrees" must not come...

Categories

Resources