Niiee.. skrng lnjt k Metode Berikutnya....
package tugas;
import java.util.Scanner;
public class secant {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
System.out.printf(“Tebakan ke – 1 : “);
double tebakan1 = s.nextDouble();
System.out.printf(“Tebakan ke – 2 : “);
double tebakan2 = s.nextDouble();
System.out.printf(“Galat : “);
double galat= s.nextDouble();
System.out.printf(“Max Iterasi : “);
int maxiterasi = s.nextInt();
double xold = tebakan1;
double xnow = tebakan2;
double yold = fungsi (xold);
double ynow = fungsi (xnow);
int iterasi = 0;
while ((Math.abs(ynow)>=galat)&(iterasi <=maxiterasi));
{
iterasi+=1;
double xnew = xnow-ynow*((xnow-xold)/(ynow-yold));
double ynew=fungsi(xnew);
xold = xnow;
yold = ynow;
xnow = xnew;
ynow = ynew;
System.out.println(“Hasil Iterasi ke- “+iterasi+” dititik x = “+xnow+” dengan nilai “+ynow);
}
if(iterasi<=maxiterasi)
{
System.out.println(“Mungkin tidak ada akar, karena melebihi maximum iterasi”);
}
}
static double fungsi(double z)
{
return Math.exp(-z)-z;
}
}