feb 2015 problem 9 and 10

This commit is contained in:
Xevion
2020-02-20 05:44:14 -06:00
parent 7746160776
commit cc21edafca
4 changed files with 88 additions and 0 deletions

View File

@@ -0,0 +1,9 @@
# Radians
Run my solution on **[repl.it](https://repl.it/@Xevion/A-Computer-Science-February-2015-Radians)!**
This problem was rather simple to implement, although, it did trip me up when it specified that everything `must be in terms of PI`. I didn't get that essentially you have to divide the converted radians to PI, so it helps to remember the meaning of that sentence (but I did later notice and correct this).
Otherwise, implementation is self explanatory and requires no extraneous thought. For those not aware, the method `Math.toRadians` can be used to convert degrees to radians easily, which is very important to remember should one be programming in JCreator, or an IDE with no built-in/enabled code completion/code intelligence plugins.
I recommend using `String.format` for this problem deeply, as it helps with rounding off the decimal radians measure quickly.

View File

@@ -0,0 +1,23 @@
import static java.lang.System.out;
import java.util.Scanner;
import java.util.Arrays;
import java.io.File;
import java.io.IOException;
class Main {
public static void main(String[] args) throws IOException {
Scanner s = new Scanner(new File("radians.dat"));
while(s.hasNextInt()) {
int degrees = s.nextInt();
double rad = Math.toRadians(degrees) / Math.PI;
String radians;
if(rad == 1)
radians = "";
else if(rad % 1 == 0)
radians = Integer.toString((int) rad);
else
radians = String.format("%.2f", rad);
out.println(String.format("%s degrees = %sPI radians", degrees, radians));
}
}
}