The program below is the answer to Liang’s Introduction To Java Programming (9th Edition) Chapter 1 Exercise 1.7.
1 2 |
/**<br /> *<br /> * @Author: Aghatise Osazuwa<br /> * Website: www.cscprogrammingtutorials.com<br /> *<br /> * Exercise 1.7 - Approximate Pi<br /> *<br /> */ <br /><br />public class Ex01_07 {<br /><br /> public static void main(String[] args) {<br /><br /> System.out.println(" 1 1 1 1 1 ");<br /> System.out.println(" Pi = 4 x (1 - - + - - - + - - - ) = " + <br /> (4 * (1.0 - (1.0 / 3) + (1.0 / 5) - (1.0 / 7) + (1.0 / 9) - (1.0 / 11))));<br /> System.out.println(" 3 5 7 9 11");<br /> System.out.println();<br /> System.out.println(" 1 1 1 1 1 1");<br /> System.out.println(" Pi = 4 x (1 - - + - - - + - - - + - ) = " + <br /> (4 * (1.0 - (1.0 / 3) + (1.0 / 5) - (1.0 / 7) + (1.0 / 9) - (1.0 / 11) + <br /> (1.0 / 13))));<br /> System.out.println(" 3 5 7 9 11 13");<br /><br /> }<br />}<br /> |
Click here to see other solutions to Introduction to Java Programming.
2 Comments
*series
I understand where the equations come into this program, but I am unsure where the series of 1's or the serious of minuses and pluses come in. Could someone please explain?