mirror of
https://github.com/Xevion/contest.git
synced 2025-12-15 08:11:27 -06:00
feb 2015 problem 9 and 10
This commit is contained in:
9
uil/aplus-february-2015/10/Radians.MD
Normal file
9
uil/aplus-february-2015/10/Radians.MD
Normal 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.
|
||||
23
uil/aplus-february-2015/10/Radians.java
Normal file
23
uil/aplus-february-2015/10/Radians.java
Normal 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));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user