Answer to Question #251577 in Java | JSP | JSF for AYESHA

Question #251577

Write a static method to return a double (parameter) rounded to the nearest 100th. Use the Math class' round method. Put this method in a class called My Math. Hints: multiply the double parameter by 100, round that, divide the rounded result by 100. Write a method to print a number (double parameter), its square and its cube, all rounded to the 100th, calling the round100th method created earlier in My Math class, but put this method in another class called Try My Math. Write a Java application program (main) that calls the method written earlier My Math class, passing Math .E in main. Put main in the Try My Math class.


1
Expert's answer
2021-10-18T00:14:47-0400

Source code

import java.lang.Math;  
public class TryMyMath{
    public static void display(double n){
        System.out.println("Number = " + MyMath.round100th(n));
        System.out.println("Square = " + MyMath.round100th(n*n));
        System.out.println("Cube   = " + MyMath.round100th(n*n*n));
    } 
    public static void main( String [] args ){
        display(Math.E);
    } 
}
class MyMath{
    public static double round100th(double n){
	   return Math.round(n*100.)/100.0 ;
	} 
}


Output


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS