Create a complete and correct Java program which performs asfollows. 1. Ask the
ID: 3611196 • Letter: C
Question
Create a complete and correct Java program which performs asfollows.
1. Ask the user to input a value for x.
2. Ask the user to input a value for the maximum exponent tocompute
2. Compute and output an approximate value for sin(x), usingthe
sin(x) equation shown above.
When doing this, only compute up to the user's desiredmaximum exponent.
The equation for sin(x)
3 5 7
x x x
sin(x) = x - --- + --- - --- + .......
3! 5! 7!
My design layout:
import java.util.Scanner;
public class SinV
{
public static void main(String Args[])
{
Scanner scan = new Scanner(System.in);
System.out.print("Input X (Radians): ");
double x = scan.nextDouble();
System.out.print("Input max exponent: ");
int expo = scan.nextInt();
double f = sin(expo);
System.out.println("The approximated sine value is: " +f);
}
// my comments
public static double sin(double expo)
{
double factor = 1;
for (int i=1;i<= expo;i+=3)
{
factor = factor*i;
}
return factor;
}
}
Okay, so approaching this problem, I see the occurance of -+, sonaturally something is being multipled by -1. Design process for anexponent without using pow function or any math function seemsimpossible to me for designing this. Can someone throw some tips onapproaching this?
Explanation / Answer
please rate - thanks should get you started. import java.util.Scanner; public class SinV { public static void main(String Args[]) { Scanner scan = new Scanner(System.in); System.out.print("Input X (Radians): "); double x = scan.nextDouble(); System.out.print("Input max exponent: "); int expo = scan.nextInt(); double f = sin(expo,x); System.out.println("The approximated sine value is: " +f); } // my comments public static double sin(double expo, double x) {int flip=-1; double factor = x; for (int i=3;iRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.