Java please help Usually in our class we just Import javauti

Java please help.

Usually in our class we just Import java.util.Scanner;

the public class

and have public staic void main(String[ ]args) but in comments before have @param args Command line arguments (not used)

Expression Evaluator.java Requirements: Calculate the following expression for a value x of type double which is read in from the keyboard, and save the result of the expression in a variable of the type double. You must use the s abs0 and pow0 methods of the Math class to perform the calculation. You grt0, may use a single assignment statement with a single expression, or you may break the expression into appropriate multiple assignment statements. The latter may easier to debug if you are not getting the correct result. (3x 2x3)2 16x7 1 Next, determine the number of digits to the left and to the right of the decimal point in the unformatted result. Hint: You should consider converting the type double result into a String using the static method Double to String(result and storing it into a String variable. Then, on this String variable use the index method from the String class to find the position of the period (i.e., decimal point) and the length method to find the length of the String. Knowing the location of the decimal point and the length, you should be able to determine the number of digits on each side of the decimal point.] Finally, the result should be printed using the class java.text.DecimalFormat so that to the right of the decimal there are at most five digits and to the left of the decimal each group of three digits is separated by a comma in the traditional way. Also, there should also be at least one digit on each Page 1 of 5 Project: Using Java API Classes Page 2 of 5 de of the decimal (e.g., 0 should be printed as 0.00. Hint: Use the pattern \"#,##0.OR###\" in your DecimalFormat constructor. However, make sure you know what this pattem means and how to modify and use it in the future. Design Several examples of input/output for the ExpressionEvaluator program are shown below. Line number Program output alue fo Enter Resul 0.2 digits to left of decimal point: 1 digits to right of decimal point 1 Formatted Result Line number Program output alue fo Enter Resul 14264.1571 14937527 digits to left of decimal point: 5 digits to right of decimal point: 12 Formatted Result: 14,264.157 11 Line number Program output alue fo Enter 10.5 Resul 9651967.17 585 digits to left of decimi al point

Solution

Hi buddy, I\'ve written the java program and also I\'ve added comments for your better understanding

import java.io.*;
import java.util.*;
import java.text.DecimalFormat;

/**
*
* @author PrudhviNIT
*/
public class ExpressionEvaluator{

/**
* @param args the command line arguments
*/
public static void main(String[] args) throws IOException{
// TODO code application logic here
Scanner obj = new Scanner(System.in);
System.out.println(\"Enter the value of x\");
double x = obj.nextDouble();
//Calculating the numerator
double numerator = Math.pow((3*Math.pow(x, 5) - 2*Math.pow(x, 3)),2);
//Calculate the denominator
double denom = Math.sqrt(Math.abs(16*Math.pow(x, 7)))+1;
//Result is numerator/denominator
double result = numerator/denom;
System.out.println(\"Result : \"+result);
//Converting the result double value to string
String res = Double.toString(result);
//Finding the index of .
int dot = res.indexOf(\'.\');
//Length of the string
int len = res.length();
//Number of digits in the left
int left = dot;
//Calculating the number of digits in the right
int right = len-dot-1;
System.out.println(\"# digits to the left of the decimal point:\"+left);
System.out.println(\"# digits to the right of the decimal point: \"+right);
//Creating a new DecimalFormat object
DecimalFormat d = new DecimalFormat(\"#,##0.0####\");
//Applying the decimalFormat and printing the result
System.out.println(\"Formatted result: \"+d.format(result));
}
}

Java please help. Usually in our class we just Import java.util.Scanner; the public class and have public staic void main(String[ ]args) but in comments before
Java please help. Usually in our class we just Import java.util.Scanner; the public class and have public staic void main(String[ ]args) but in comments before

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site