Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I need to round up a double to the nearest highest int and I just stumbled across the ceil() method. I'm not quite sure what I'm doing wrong but it is not working as expected. I wrote this code to try to troubleshoot what I'm doing wrong but I can't figure out. I expected this to print '1.0' since .75 rounded up is 1.
int d=3;
int b= 4;
double c=Math.ceil(d/b);
System.out.println(c);
you have to cast it first
double c=Math.ceil((double)d/b);
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 17 days ago.
Improve this question
I am trying to produce all permutations of an array of size N (i.e. N = 9) with possible elements Z (i.e. Z = [0,1,2,3,4])
Duplicates are allowed, but there needs to be at least one. I am able to write the algorithm to go through all possibilities but the minimum of at least one of each of Z is the part I'm having trouble with.
Looking to do this algorithm in java. Can someone help?
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
My Friend ask me this question and i am posting it here, if you have better approach please share
String getRandomMobileNumber() {
double random = Math.random();
Double randomten = random*1000000000.0;
return "0"+Math.round(randomten);
}
You can use this, see javadoc:
String phoneNumber = "0" + ThreadLocalRandom.current().nextInt(10000000, 99999999);
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I tried it with Sieve Of Eratosthenes, but I quickly run into the problem that my boolean array can't go past Integer.MAX
How should I approach this problem?
Arrays
Use 2 or more dimensional maps. So converting long to two integers (for accessing the arrays) will be like this:
array[N / Integer.MAX_VALUE][N % Integer.MAX_VALUE] where N is long and array is the boolean array.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
double ps1 = (double) (((double)1)/(double)100);
int maz = (double) ((ps1) * Double.parseDouble(500000.102)));
Is this right to use double, or shall i use long?
I am doing large calculations. And need to keep the correctness of the .102.
Use double! Because long has no signs after , (they have no fraction)
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
How to handle 1000 digit number? Anyone can explain it?
My code;
Long sum = 1L;
...
if (String.valueOf(sum).length() == 1000) {
...
}
But not working, anyone can explain it?
Use the class BigInteger, it can handle arbitrary long numbers (that is, as big as computer memory allows).
Link: http://docs.oracle.com/javase/7/docs/api/java/math/BigInteger.html
Use a BigInteger instead. See the documentation here.