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.
Related
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 tried compiling my code so I could then run it and test it, but it says that there is a semi-colon expected.
I tried deleting and re-inserting the semi-colon, but the error keeps appearing when I compile. The error is "GPACalculator.java:430: error: ';' expected"
if ((class71Honors.equals("Yes"))||(class71Honors.equals("Yes."))||(class71Honors.equals("yes"))||(class71Honors.equals("yes.")))
{
double class71GPA+=0.6;
}
I don't expect a printed output, I just want the code to compile because it's the only error I have at the moment. Thanks! (this is all java by the way)
This is invalid syntax.
double class71GPA+=0.6;
First you need to define and initialize your variable:
double class71GPA = 0;
And after that you can use it in statements. In your case:
class71GPA += 0.6;
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.
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());
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);
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...