Java Question Base on this code TryMyMathjava import javauti

Java Question:

Base on this code

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); }

}

1. Write a Java application program (main) that calls the method written in the codes above, passing (1000.*Math.E) in main. Put main in the TryMyMath class.

Solution

package org.students;

import java.util.Scanner;

public class TryMyMath {
   public static void main(String[] args) {
       //Scanner Object is used to read the inputs entered by the user
       Scanner scan = new Scanner(System.in);
      
       //Getting the number entered by the user
       System.out.println(\"Enter Number: \");
       double n = scan.nextDouble();
      
       //Calling the method root() by passing the number as argument
       root(n);
      
       //Calling the method round100th() by passing the number as argument
       n = round100th(n);
      
       //Displaying the Rounded value
       System.out.println(\"Rounded: \" + n);
      
       System.out.println(\"___________________\");
      
       //calling the method root() again by passing \" 1000.*Math.E \" as argument
       root(1000.*Math.E);
      
       //calling the method round100th() again by passing \" 1000.*Math.E \" as argument
       double n1 = round100th(1000.*Math.E);
      
       //Displaying the rounded values as output on console
       System.out.println(\"Rounding of \"+1000.*Math.E+\" is : \" + n1);
   }

   /*This method will round the number to nearest 100th value
   * Params: number of double type
   * Return :rounded number of double type
   */
   public static double round100th(double n) {
       n = Math.round(n / 100);
       n = n * 100;
       return n;
   }

   /*
   * This method will calculate the square root and
   * cube root of a number and display the output on the console
   * Params : number of double type
   * Return : void
   */
   public static void root(double n) {
      
       //calculating the Square root of a number
       double squareRoot = Math.sqrt(n);
      
       //calculating the Cube root of a number
       double cubeRoot = Math.cbrt(n);
      
       //Displaying the Square root of a number
       System.out.println(\"Square root of \"+n+\" is \" + squareRoot);
      
       //Displaying the Cube root of a number
       System.out.println(\"Cube root \"+n+\" is \"+ cubeRoot);
   }
}

__________________________________________

Output:

Enter Number:
77
Square root of 77.0 is 8.774964387392123
Cube root 77.0 is 4.254320865115006
Rounded: 100.0
___________________
Square root of 2718.2818284590453 is 52.13714442179438
Cube root 2718.2818284590453 is 13.956124250860896
Rounding of 2718.2818284590453 is : 2700.0

__________________________________Thank You

Java Question: Base on this code TryMyMath.java import java.util.Scanner; public class TryMyMath { public static void main(String[] args) { Scanner scan = new S
Java Question: Base on this code TryMyMath.java import java.util.Scanner; public class TryMyMath { public static void main(String[] args) { Scanner scan = new S

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site