Java:User Enter Antilog Base issue? -
i'm finding anti-logarithm of enter values.answer right natural log base.but when try find anti-log enter base.then doesn't give correct answer such as
anti-log value 10 base 10 = 10000000000
code:
public class { public static void main(string[] args) { scanner s = new scanner(system. in ); double value, res, value2, res2; system.out.print("enter anti log value:"); value = s.nextdouble(); res = math.exp(value); system.out.println("answer of antilog natural base is: + res); system.out.println("-----------------------------------"); system.out.print("enter base:"); value2 = s.nextdouble(); res2 = math.exp(value) / math.exp(value2); system.out.println("answer of antilog enter base : " + res2); } }
it give answer enter base 10 = 1.0 how fix this.
assuming understand question correct should replace
res2 = math.exp(value) / math.exp(value2);
with
res2 = math.pow(value2, value);
if want avoid scientific notation when printing value, use:
system.out.printf("answer of antilog enter base : %f%n", res2 );
or (to skip decimals):
system.out.printf("answer of antilog enter base : %.0f%n", res2 );
Comments
Post a Comment