In: Computer Science
Write a program to use Math methods to calculate and display the followings:
Evaluate all your answers to avoid shock & regret.
Display meaningful output for each task.
You only need to check if the input is valid in requirement # 2. For all the others, you can assume valid input is entered.
In JAVA
MathDemo.java
import java.util.Scanner;
public class MathDemo {
public static void main(String[] args) {
double angle = 0.0;
Scanner scan = new
Scanner(System.in);
System.out.println("Enter angle in
degrees: ");
angle = scan.nextDouble();
System.out.println("Angle in
radians: " + Math.toRadians(angle));
System.out.println("Sine (" + angle
+ ") = " + Math.sin(Math.toRadians(angle)));
int number = 0;
//Continue asking for positive number, until positive number is
entered
do {
System.out.println("Enter a positive integer: ");
number =
scan.nextInt();
}while(number<0);
System.out.println("Square root of
" + number + " is " + Math.sqrt(number));
int m, n;
System.out.println("Enter m:
");
m = scan.nextInt();
System.out.println("Enter n:
");
n = scan.nextInt();
System.out.println("m^n = " +
Math.pow(m, n));
double decimal = 0.0;
System.out.println("Enter a decimal
number: ");
decimal = scan.nextDouble();
System.out.println("Decimal number
rounded: " + Math.round(decimal));
System.out.println("Decimal number
floor: " + Math.floor(decimal));
System.out.println("Decimal number
ceiling: " + Math.ceil(decimal));
System.out.println("Enter upper
bound of random number: ");
int U = scan.nextInt();
System.out.println("Enter lower
bound of random number: ");
int L = scan.nextInt();
//Find random number, as given in the question
int rand = L + (int)(Math.random()
* (U-L+1));
System.out.println("Random number
between " + L + " & " + U + " is " + rand);
}
}