How I can handle 1000 digit numbers in Java ? [closed] - java

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.

Related

How to generate a random mobile number starts with zero and have 10 digits, that starts with zero? [closed]

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);

How do I efficiently generate Prime Numbers up until 3037000499 (the square root of Long.MAX)? [closed]

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.

Issues with math.ceil [closed]

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);

Java BigInteger OR function [closed]

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
I am using Java and have some problems.
I made two BigInteger variables, p and q.
In my code, I want to add if function, like if(p=1 \ q=1).
I tried many ways but there was error. Do you know how to solve this?
Your question is not completely clear, but you need to use the BigInteger.equals() method, as in this example:
if (BigInteger.equals(p, BigInteger.ONE) || BigInteger.equals(q, BigInteger.ONE)) {
// do something
}

double , long in Java use [closed]

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)

Categories

Resources