Write a Math class java program with pow abs and sqrtSolutio
Write a Math class java program with pow, abs and sqrt.
Solution
I think this is what you requested for.If you want any modifications.Just tell me.thank you.
____________________
MathClassMethods.java
import java.util.Scanner;
public class MathClassMethods {
   public static void main(String[] args) {
        //Declaring variables
        int number,power,negnum,numsqrt;
       
        //Scanner class Object is used to read the inputs entered by the user
        Scanner sc=new Scanner(System.in);
       
        //Getting the number entered by the user
        System.out.print(\"Enter a number :\");
        number=sc.nextInt();
       
        //Getting the power entered by the user
        System.out.print(\"Enter the Power :\");
 power=sc.nextInt();
   
 //Displaying the number when it was raised to the power
 System.out.println(number+\"^\"+power+\" is \"+Math.pow(number,power));
   
 //Getting the negative number entered by the user
 System.out.print(\"Enter a Negative Number :\");
 negnum=sc.nextInt();
   
 //Displaying the absolute value of the negative number entered by the user
 System.out.println(\"The absolute value of \"+negnum+\" is \"+Math.abs(negnum));
   
 //Getting the number entered by the user to find the square root
 System.out.print(\"Enter a number to find Square root :\");
 numsqrt=sc.nextInt();
   
 //Displaying the square root of the entered number
 System.out.println(\"The Square root of \"+numsqrt+\" is \"+Math.sqrt(numsqrt));
    }
}
___________________________
output:
Enter a number :5
 Enter the Power :3
 5^3 is 125.0
 Enter a Negative Number :-56
 The absolute value of -56 is 56
 Enter a number to find Square root :64
 The Square root of 64 is 8.0
_______________Thank You


