Question

In: Computer Science

UseMath Write a program called UseMath. It should contain a class called UseMath that contains the...

 

UseMath

Write a program called UseMath. It should contain a class called UseMath that contains the method main. The program should ask for a number from the user and then print the information shown in the examples below. Look at the examples below and write your program so it produces the same input/output.

Examples

(the input from the user is in bold face) % java UseMath enter a number: 0 the square root of 0.0 is: 0.0 rounded to the nearest integer: 0 the value of PI is: 3.141592653589793 the value of PI plus your number is: 3.141592653589793 rounded to the nearest integer: 3 the value of E plus your number is: 2.718281828459045 the absolute value of your number is: 0.0 % java UseMath enter a number: 1 the square root of 1.0 is: 1.0 rounded to the nearest integer: 1 the value of PI is: 3.141592653589793 the value of PI plus your number is: 4.141592653589793 rounded to the nearest integer: 4 the value of E plus your number is: 3.718281828459045 the absolute value of your number is: 1.0 % java UseMath enter a number: -1 the square root of -1.0 is: NaN rounded to the nearest integer: 0 the value of PI is: 3.141592653589793 the value of PI plus your number is: 2.141592653589793 rounded to the nearest integer: 2 the value of E plus your number is: 1.718281828459045 the absolute value of your number is: 1.0 % java UseMath enter a number: .5 the square root of 0.5 is: 0.7071067811865476 rounded to the nearest integer: 1 the value of PI is: 3.141592653589793 the value of PI plus your number is: 3.641592653589793 rounded to the nearest integer: 4 the value of E plus your number is: 3.218281828459045 the absolute value of your number is: 0.5 % java UseMath enter a number: .1 the square root of 0.1 is: 0.31622776601683794 rounded to the nearest integer: 0 the value of PI is: 3.141592653589793 the value of PI plus your number is: 3.241592653589793 rounded to the nearest integer: 3 the value of E plus your number is: 2.818281828459045 the absolute value of your number is: 0.1 % java UseMath enter a number: 10 the square root of 10.0 is: 3.1622776601683795 rounded to the nearest integer: 3 the value of PI is: 3.141592653589793 the value of PI plus your number is: 13.141592653589793 rounded to the nearest integer: 13 the value of E plus your number is: 12.718281828459045 the absolute value of your number is: 10.0 %

Solutions

Expert Solution

if you have any doubts, please give me comment...

import java.util.Scanner;

public class UseMath{

    public static void main(String[] args) {

        Scanner scnr = new Scanner(System.in);

        System.out.print("enter a number: ");

        double num = scnr.nextDouble();

        double sqrtNum = Math.sqrt(num);

        System.out.println("the square root of "+num+" is: "+sqrtNum+" rounded to the nearest integer: "+Math.round(sqrtNum));

        System.out.println("the value of PI is: "+Math.PI);

        System.out.println("the value of PI plus your number is: "+(Math.PI+num)+" rounded to the nearest integer: "+Math.round(Math.PI+num));

        System.out.println("the value of E plus your number is: "+(Math.E+num));

        System.out.println("the absolute value of your number is: "+Math.abs(num));

    }

}


Related Solutions

AskInfoPrintInfo Write a program called AskInfoPrintInfo. It should contain a class called AskInfoPrintInfo that contains the...
AskInfoPrintInfo Write a program called AskInfoPrintInfo. It should contain a class called AskInfoPrintInfo that contains the method main. The program should ask for information from the user and then print it. Look at the examples below and write your program so it produces the same input/output. Examples (the input from the user is in bold face) % java AskInfoPrintInfo enter your name: jon doe enter your address (first line): 23 infinite loop lane enter your address (second line): los angeles,...
Java program Write a class called Animal that contains a static variable called count to keep...
Java program Write a class called Animal that contains a static variable called count to keep track of the number of animals created. Your class needs a getter and setter to manage this resource. Create another variable called myCount that is assigned to each animal for each animal to keep track of its own given number. Write a getter and setter to manage the static variable count so that it can be accessed as a class resource
Write a C++ program test.cpp. The class should contain a protected int member variable var, which...
Write a C++ program test.cpp. The class should contain a protected int member variable var, which is initialized with an integer value between 1 and 50 in a constructor that takes an integer parameter. The class should contain a public member function called play that should print out a sequence of integers as a result of iteratively applying a math function f to the member variable var. The function f is defined as f(x) = (3x+1)/2 if x is odd...
Write a program that uses an array for time and temperature. The program should contain an...
Write a program that uses an array for time and temperature. The program should contain an array with 24 elements, each of which is holding a temperature for a single hour. Your program should have a function that lists all of the temperatures that are held in the array. Temperatures should be listed to console with one entry per line. Your program should have a function that lists a single temperature entry. You should ask the user for a number...
The Tokenizer.java file should contain: A class called: Tokenizer Tokenizer should have a private variable that...
The Tokenizer.java file should contain: A class called: Tokenizer Tokenizer should have a private variable that is an ArrayList of Token objects. Tokenizer should have a private variable that is an int, and keeps track of the number of keywords encountered when parsing through a files content. In this case there will only be one keyword: public. Tokenizer should have a default constructor that initializes the ArrayList of Token objects Tokenizer should have a public method called: tokenizeFile tokenizeFile should...
Write a class called Animal that contains a static variable called count to keep track of...
Write a class called Animal that contains a static variable called count to keep track of the number of animals created. Your class needs a getter and setter to manage this resource. Create another variable called myCount that is assigned to each animal for each animal to keep track of its own given number. Write a getter and setter to manage the static variable count so that it can be accessed as a class resource
Write a recursive method to determine if a String is a palindrome. The program should contain...
Write a recursive method to determine if a String is a palindrome. The program should contain a String array that you can load several test cases to test your palindrome testing method. The program should load your String Array with the test data containing the possible palindromes from a text file. The program should test you application with a text file contained in your project folder After testing your program with your test cases in the text file, you program...
Write a recursive method to determine if a String is a palindrome. The program should contain...
Write a recursive method to determine if a String is a palindrome. The program should contain a String array that you can load several test cases to test your palindrome testing method. The program should load your String Array with the test data containing the possible palindromes from a text file. The program should test you application with a text file contained in your project folder After testing your program with your test cases in the text file, you program...
3. write a program that uses a class called "garment" that is derived from the class...
3. write a program that uses a class called "garment" that is derived from the class "fabric" and display some values of measurement. 20 pts. Based on write a program that uses the class "fabric" to display the square footage of a piece of large fabric.           class fabric            {                private:                    int length;                    int width;                    int...
write a program in java that contain a class for botique . data member include code...
write a program in java that contain a class for botique . data member include code , color , size , quantity . your class should contains all accessor and mutator methods , non paraqmetric constructor , parametric constructor , input andvidsplay method
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT