java - To give two decimals using printf from doubles and input tsking -


expected input: x=1.75 y=1.25 z=0.75 answer 0.95  program output: enter value of x: 1.75 exception in thread "main" java.util.inputmismatchexception @ java.util.scanner.throwfor(scanner.java:864) @ java.util.scanner.next(scanner.java:1485) @ java.util.scanner.nextint(scanner.java:2117) @ java.util.scanner.nextint(scanner.java:2076) @ evaluate.main(evaluate.java:13)     import java.util.scanner;   //make scanner class available public class evaluate { public static void main(string[] args) { scanner input=new scanner(system.in); double x=0.0; double y=0.0; double z=0.0; double ans; ans=(x*y-y*z)/x*z ; system.out.println("enter value of x:"); //take input  x=input.nextint(); system.out.println("enter value of y:");   

the code meant evaluate expression ansa , produuce answer 2 decimal places having viriables declared doubles. appreciate.

y=input.nextint(); system.out.println("enter value of z:");  //take value of z z=input.nextint(); system.out.printf("the answer ","%0.2f%ans",ans); //get 2 decimals  } } 

the nextint function reads ints. need use nextdouble function read double.

also, need calculation after input doubles.


Comments

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -