From the textbook, do Exercises 5.16, 6.15, 6.26, 6.40 (also note extra instructions below).
To do these exercises, you will need the MyInput class that was used in lecture and in HW 1. You actually do not need to paste a full copy of this file into your other program files. If you have a copy of MyInput.java in the same directory with your other program files, your compilations should work. (I'll demonstrate this in class).
In addition to the method, write a main method that asks the
user to input a positive integer N. Using your prime() method,
find and print all the prime numbers less than or equal to N, 10 numbers
per line.
Also write a sample main program that asks the user to
input two positive integers and then calls the GCD method and prints the
result. (Note: positive number means > 0).
GCD(m,n) is m, if n is equal to zero. GCD(m,n) is GCD(n, m%n) otherwise
GCD(m,n) is m, if m equals n. GCD(m,n) is GCD(m - n, n) if m is greater than n. GCD(m,n) is GCD(m, n - m) otherwise.
Exercise 5.16: 'Approximating PI' Compute to how many terms of the series? 20 terms PI approximation 1 4.0 2 2.666666666666667 3 3.466666666666667 4 2.8952380952380956 5 3.3396825396825403 6 2.9760461760461765 7 3.2837384837384844 8 3.017071817071818 9 3.2523659347188767 10 3.0418396189294032 11 3.232315809405594 12 3.058402765927333 13 3.2184027659273333 14 3.0702546177791854 15 3.208185652261944 16 3.079153394197428 17 3.200365515409549 18 3.0860798011238346 19 3.1941879092319425 20 3.09162380666784
Exercise 6.15: 'hypotenuse' Enter first leg of right triangle: 3 Enter second leg of right triangle: 4 Length of hypotenuse = 5.0
Exercise 6.15: 'hypotenuse' Enter first leg of right triangle: 10.5 Enter second leg of right triangle: 16 Length of hypotenuse = 19.13765920900464
Exercise 6.26: 'Primes' Please input a positive number: 500 The prime numbers less than or equal to 500 are: 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 401 409 419 421 431 433 439 443 449 457 461 463 467 479 487 491 499
Programming Exercise 6.40 'GCD recursive' Input first number : 45 Input second number : 10 GCD(45, 10) = 5
tar cvf hw2.tar Ch5_16.java Ch6_15.java Ch6_26.java Ch6_40.javaOr, if you have all your .java files for this one in a single directory:
tar cvf hw2.tar *.javaE-mail this tar file to me (myers@cs.fsu.edu) by the due date. Your e-mail subject should be HW2-SUBMIT. Include your name and section in the e-mail body. Please only submit ONCE, unless you make a mistake and need to correct it (before the due date) -- and minimize this. Only the last submission will be graded.