You intended to declare 2 functions, f
and df
before the main
function, then define both f
and df
. You're allowed to do this kind of things in C, but this is not C, is Java.
In Java, you can only declare classes and interfaces at the top level, and the methods are defined inside them. So, these functions are invalid, along with their definitions below the class:
import Scanner.java.util;
//invalid
double f = (double);
//invalid
double df = (double);
public class NewtRaphEx {
//class content...
}
//invalid
// Creating Function f = x - cos(3.5x)
double f(double x) {
return (x - cos(3.5 * x))
}
//invalid
double df (double x) {
return (1 + sin(3.5 * x))
}
To make your application work, one way would be to redefine these functions as static
methods inside your class.
import Scanner.java.util;
public class NewtRaphEx {
//valid
// Creating Function f = x - cos(3.5x)
static double f(double x) {
return (x - cos(3.5 * x))
}
//valid
static double df (double x) {
return (1 + sin(3.5 * x))
}
//class content...
}
I highly recommend you to review the basics of Java programming by following The Java Tutorials.