simple java program
Java Programming
1. Create a class called Project8 and implement the following methods:
a. (factorial) write a method that calculates and return n!
b. (computing Π(pi)) You can approximate Π by using the following series:
Π = 4(1 – 1/3 + 1/5 – 1/7 + 1/9 – 1/11 + …. + 1/2n-1 – 1/2n+1)
Write a method called pi, that given n, calculates and return value of Π
c. (Approximating the square root) Implement the sqrt method. The square root of a number, num, can be approximated be repeatedly performing a calculation using the following formula:
nextGuess = (lastGuess + (num / lastGuess)) / 2
When next Guess and lastGuess are almost identical, nextGuess is the approximated square root.
The initial guess can be any positive value (e.g., 1). This value will be the starting value for lastGuess. If the difference between nextGuess and lastGuess is less than a very small number, such as 0.0001, you can claim that nextGuess is the approximated square root of num. If not, nectGuess becomes lastGuess and the approximation process continues.
d. (Convert form decimal to other bases) Write a method that converts decimal numbers to other bases (binary, octal, hexadecimal).
2. Write a main method to the following:
a. Calculates and prints value of Π for n=10000
b. Calculate and print square root of 16
c. Convert 125 to binary, octal, and hexadecimal
A sample run is as follows:
8! is: 40320
Value of pi is 3.1415826535898224
Square root of 16 is 4.000000000000051
125 in Binary is 1111101
125 in Octal is 175
125 in Hexadecimal is 7D
12 years ago 5
Purchase the answer to view it
- simple_java.docx
Purchase the answer to view it
Purchase the answer to view it
- bqookq.zip
- Strategic management
- Math Question
- a paper of no more than 350 words after completing
- <p>i would like you to meet janine lee. One of my good friends from high school.</p>
- ACC 421 MCQ'S(36 MCQ'S Answered)
- ACC 291 Complete Week 2
- ENG 221 Week 3 Individual Assgnment; Request for Proposal for Microsoft¬ Office¬ Programs Trainer.docx
- Communication strategies.
- accounting homework
- FIN 467 Final Exam MCQ Solutions (A+ Guaranteed)