In this java program fixed this code because there is an error. After you fixed the code please run the program and show the output of this code. Thank you.
In this java program fixed this code because there is an error. After you fixed the code please run the program and show the output of this code. Thank you.
Source Code:
// Online Java Compiler
// Use this editor to write, compile and run your Java code online
import java.lang.*;
import java.util.*;
class HelloWorld {
float ln(int x, int y){
lnX = Math.log(x);
lnY = Math.log(y);
ln = lnX + lnY;
return ln;
}
public static void main(String[] args) {
System.out.println("Enter lower limit:-");
Scanner sc= new Scanner(System.in);
int lower = sc.nextInt();
System.out.println("Enter higher limit:-");
int higher = sc.nextInt();
int iterations = (higher -1)/0.05;
float y = 1.05;
float final_answer = 0;
for(int i=0;i<iterations;i++){
float ans = ln(lower, y);
lower += 0.05;
y = lower + 0.05;
final_answer += ans;
int x = Math.round(lower,2);
x = Math.round(x,2);
y = math.round(y,2);
System.out.println("_________________________________________________________________________________________________________________");
System.out.println("Iteration:"+Math.round(x,2));
System.out.println("Function\\|\Lower Limit \|\ Upper Limit \|\ Trapezoid Application (width=0.05) \|");
System.out.println("(ln(x)+ln(x)/2)1 \|\x="+Math.round(x,2)+"\|\x="+Math.round(y,2),"\|\ (ln("+x+")+ln("+y+")/2)1\|\\Answer: "+ans);
}
System.out.println("_________________________________________________________________________________________________________________");
System.out.println("\\Total Iterations:"+Math.round(x,2));
System.out.println("Final Answer/Summation of all iterations:"+final_answer)
}
}
See the picture below that's an sample output of the program.
Step by step
Solved in 3 steps with 2 images