A Java Course Outline
Using the Java By Dissection book
by Ira Pohl and Charlie McDowell


Solution to Homework 3 - Find root (easy way)

Excellent program, good use of variable names, nice output.

/*Maya Thornton
This assignment will create a program which can find the root of the equation F(x)=sin(x) - cos(x) */ class EquationRoot { public static void main (String[] args) { double x; double F; double lowest=2; // "lowest" represents a place to store our closest value to zero double solution=0; //"solution" represents the value of 'x' that solves the root for( x=0; x<2; x=x + 0.001) { F = Math.sin(x) - Math.cos(x); if (Math.abs(F) < Math.abs(lowest)) { lowest = F; solution=x; }//end of "if" statement }//end of "for" loop System.out.println("The root of F(x)=sin(x)-cos(x) is " + lowest); System.out.println("The root of F(x)=sin(x)-cos(x) occurs at x=" + solution); }//end of main }//end of class

Feel free to report any site problems to the Webmaster, Debra Dolsberry.