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 8 years ago.
Improve this question
I am solving a problem for which i require to know the number of 1 bit's in a BigInteger.
Thanks in advance.
You can use .bitCount() on the BigInteger. Unless you need to solve it manually, in which case you can use normal Java bitwise operations.
Do x-or with 0. By this you will get the bits set as 1 wherever there was 1 in your original input. Then you can count the number of bits set in the output.
Related
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 2 years ago.
Improve this question
Why it's showing error, when I enter just 5 digit number in long data type?
Numbers starting with 0 are interpreted as octal numbers in Java, that are 8-based numbers. A 9 or 8 cannot appear in octal number, thus the warning.
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 4 years ago.
Improve this question
Is there any way to print a fraction in any form? I'm working on a math program and a fraction is much easier to read than 1/2.
If there is any API that can do written math, I would also be glad.
Example:
Instead of 1/2
There isn't a one-liner answer for your question, so try approaching it from a different angle. You could write a method that takes the numerator and denominator as arguments and then return an output string in any format you want, such as String.format("%d\n---\n%d",numerator,denominator);
if your printing it without quotes your pretty much just turning it into a decimal because your dividing the 2. An example to avoid this:
System.out.println("1/2");
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 6 years ago.
Improve this question
For example, if I have a string (24/25), how would I go about being left with two double values of 24 and 25. My objective to to eventually, given a set of number of that form, divide each of them, and add to get the average. I'm fairly new to Java and I honestly am so confused as where to even begin. Thank you!
As Andreas said. First you need to take the substring between brackets. Use String.substr
Now split 24/25 to 24 and 25. You can use String.split
Then you can parse them with Double.parse
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 6 years ago.
Improve this question
I have a file "file.txt" in Java. In the file I have the following values:
10 10
3 3 W
MMMMMRM
4 4 R
LRLRLML
I want to read each line and with each character I want to assign them to a variable which I will use for calculation.
Any idea with how I can proceed with?
Thanks
1) You can use a BufferedReader with the readLine() method to read each line.
2) Then you can use split() for each word or toCharArray() for each character.
3) Then assign said character to predefined variables.
It would be helpful if we could see what you've tried so far or if you could give more details on what you are trying to accomplish.
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 8 years ago.
Improve this question
it is possible to assign that big number in java? i need to make a calculation of 39 digits value. could any help? Thanks
Problem:
Consider the following composite number:
340282367237851113557325445936183246849
Write a Java method to find two numbers whose product is the above number.
I guess you need to check out the BigInteger of the java API. That might be able to store your results of those much big numbers. Read the documentation,
http://docs.oracle.com/javase/7/docs/api/java/math/BigInteger.html