Question
Print out an approximation of the mathematical constant 1. You must compute an approximation of , accurate out to at least two digits past the
Print out an approximation of the mathematical constant 1. You must compute an approximation of , accurate out to at least two digits past the decimal point, using the following inefficient) formula: 1 1 1 1 1 = 4x + 5 7 9 DO NOT just print out a String-literal of an approximation, i.e., DO NOT JUST DO THIS: + 3 -+...). System.out.println(\"3.14159265359\"); Instead, compute the above expression out to as many terms as it takes to get at least two digits past the decimal point correct. You cannot use explicit type casting for computing your approximation of 2. Prompt the user to which digit past the decimal point in your approximation that they would like for your program to print out. 3. Print out the requested digit, just by itself on its own line. Your program must print out the correct digit (relative to your approximation of 7, out to the fifteenth digit past the decimal point (the first digit past the decimal point will be counted as digit 1). See the Hints section. 4. Do not do any computation steps inside of print statements. 5. Every line of code in your program must be less than or equal to 78 characters in width. Hints: Assuming something is an integer type (int or long), then the expression something % 10 evaluates to the rightmost digit of something. The expression something * 10 evaluates to a number comprised of the digits of something shifted left one position, with a 0 occupying the rightmost digit position. You can and should use Math.pow to compute a power of ten, perhaps based on user in- put, like this: Math.pow(10, ???); Just be careful, because the previous call to Math.pow evaluates to a double. Sample runs: 3.1493444751246202 Which digit past the decimal point do you want? 1 1 3.1493444751246202 Which digit past the decimal point do you want? 7 4 3.1493444751246202 Which digit past the decimal point do you want? 10 1
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started