Hi everyone, I've been given an assignment for practice and it has to do with calculating the sine again but this time I have to use modular programming. I already have a working inlined program, so I'm pretty sure I'll be able to do it.
Apparently when I tried to convert degrees to radians using a subroutine, I get an error when I run it.
Original Code
import java.io.*; public class HW6X { public static void main(String args[]) throws IOException { BufferedReader keybd = new BufferedReader(new InputStreamReader(System.in)); double x; int maxe; System.out.println("Enter a value in degrees: "); x = Double.parseDouble(keybd.readLine()); System.out.println(convert(x)); } public static double convert(double x) { x = x * Math.PI / 180; return x; } }
Error:
Exception in thread "main" java.lang.NoClassDefFoundError: HW6X/java Caused by: java.lang.ClassNotFoundException: HW6X.java at java.net.URLClassLoader$1.run(URLClassLoader.java:202) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:190) at java.lang.ClassLoader.loadClass(ClassLoader.java:307) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) at java.lang.ClassLoader.loadClass(ClassLoader.java:248) Could not find the main class: HW6X.java. Program will exit.
I tried googling this problem and others have said that it has to do with the classpath. I'm not sure what they meant by this, if it's the reason for the error. I think if I find out why this doesn't work, then I'll be able to do the rest of the program without any problem.