0

Java program for convert Angle from degree to radian

https://code.sololearn.com/cC62uSJgtqcf/?ref=app I want a program like this: 1. Ask the user to enter the angle in degrees, 2. Converts the angle from degrees to radians, the output will be as follows: Insert the angle in degree 100 It’s equal to: 1.4753293 radian Please make it as a full code And question: What is the mathematical method that calculates pi?

12th Sep 2021, 1:46 AM
STOP
STOP - avatar
2 Réponses
+ 1
import java.util.Scanner; import java.lang.Math; public class Program { public static void main(String[] args){ Scanner sc = new Scanner(System.in); System.out.println("Enter Angle"); int a = sc.nextInt(); double rad = (a * Math.PI)/180; System.out.println(rad); } } In your code, you forgot the main. The class Math gives us an approximation of pi -> Math.PI.
12th Sep 2021, 2:06 AM
Gigi
+ 1
There are already built-in methods in the Math class that will convert degrees to radians and vice-versa. Math.toRadians(degrees) Math.toDegrees(radians) Each method will take in the argument as a double and returns a double. import java.util.Scanner; public class Program { public static void main(String[] args) { System.out.println("Enter angle:"); Scanner sc = new Scanner(System.in); double deg = sc.nextDouble(); double rad = Math.toRadians(deg); System.out.println(rad); } } FYI, you don't need to import Math. java.lang.* is automatically imported by default.
12th Sep 2021, 5:12 AM
ChaoticDawg
ChaoticDawg - avatar