Is there any method of converting math formula in java [closed] - java

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
I need to convert that formula in such a way that i can make the calculation by taking the input of radix and number from user
〖log〗_radix (number)= (〖log〗_e (number))/(〖log〗_e (radix))

Well, you could simply read the inputs similar to here. Then, just calculate the result.
Scanner input = new Scanner(System.in);
double number = input.nextDouble();
double radix= input.nextDouble();
double result = Math.log(number) / Math.log(radix);

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 to take only numbers in a string? [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 4 years ago.
Improve this question
If you prompt the user for a price and they input $25.50, how would I take out the numbers and store them as a Double so that I can use them in equations.
I have tried,
System.out.println("What is the price of the product(e.g. 35.21)?");
price = scanner.nextLine();
price_2 = price.replaceAll("[^0-9]", "");
price_3 = Double.parseDouble(price_2);
System.out.println(price_3);
But it does not maintain the decimal.
You can use a regex to strip out all non-numeric characters from the String, while leaving the decimal point.
Then, just parse the string to a double:
String str = "$25.50";
double dbl = Double.parseDouble(str.replaceAll("[^0-9,.]",""));
System.out.println(dbl);
In your code, you were removing the decimal point as well. Simply add the ,. to your regex.

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

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)

Substring/toString/IndexOf Function not working past a certain value [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 8 years ago.
Improve this question
I have a function:
ItemValue[i] = substring(toString(obj),0,toString(obj).indexOf(".") + 4);
where obj is a number. The function works for 9,999,999.99999 -> 9999999.999 but values such as 99,999,999.99999 gets converted to 9.999.
Is it a data type issue?
Thanks,
The problem is with the double values you are using. The value 99999999.99999 will be translated to 9.999999999999E7 by toString() so the results you are getting. In order to strip the digits after decimal you can use DecimalFormat class:
DecimalFormat f = new DecimalFormat();
f.setMaximumFractionDigits(3);
f.setMinimumFractionDigits(3);

Categories

Resources