Java QuestionL 1 Write a method to print a number double par

Java QuestionL

1) Write a method to print a number (double parameter), its squareroot and its cube root (use the pow method to the 1./3. power), all rounded to the 100th, calling the round100th method from #1, but put this method in another class called TryMyMath

Solution

TryMyMath.java

import java.util.Scanner;


public class TryMyMath {
   public static void main(String[] args) {
       Scanner scan = new Scanner(System.in);
       System.out.println(\"Enter Number: \");
       double n = scan.nextDouble();
       root(n);
       n = round100th (n);
       System.out.println(\"Rounded: \"+n);
      
   }
   public static double round100th (double n){
       n = Math.round(n/100);
       n = n * 100 ;
       return n;
   }
   public static void root (double n){
       double squareRoot = Math.sqrt(n);
       double cubeRoot = Math.cbrt(n);
       System.out.println(\"Square root is \"+squareRoot);
       System.out.println(\"Cube root is \"+cubeRoot);
   }

}

Output:

import java.util.Scanner;


public class TryMyMath {
   public static void main(String[] args) {
       Scanner scan = new Scanner(System.in);
       System.out.println(\"Enter Number: \");
       double n = scan.nextDouble();
       root(n);
       n = round100th (n);
       System.out.println(\"Rounded: \"+n);
      
   }
   public static double round100th (double n){
       n = Math.round(n/100);
       n = n * 100 ;
       return n;
   }
   public static void root (double n){
       double squareRoot = Math.sqrt(n);
       double cubeRoot = Math.cbrt(n);
       System.out.println(\"Square root is \"+squareRoot);
       System.out.println(\"Cube root is \"+cubeRoot);
   }
}

Output:

Enter Number:
64
Square root is 8.0
Cube root is 4.0
Rounded: 100.0

Java QuestionL 1) Write a method to print a number (double parameter), its squareroot and its cube root (use the pow method to the 1./3. power), all rounded to
Java QuestionL 1) Write a method to print a number (double parameter), its squareroot and its cube root (use the pow method to the 1./3. power), all rounded to

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site