Unformatted text preview:

Newton1and2 java Thursday January 27 2022 2 16 PM 1 import components simplereader SimpleReader 5 6 7 Calculate the square root an inputed number with a given error range that is 8 compatible with 0 9 10 author Chime Nwaru 11 12 13 public final class Newton1and2 14 15 16 Private constructor so this utility class cannot be instantiated 17 18 private Newton1and2 19 20 21 22 Computes estimate of square root of x to within relative error 0 01 23 24 param x 25 positive number to compute square root of 26 return estimate of square root 27 28 private static double sqrt double x 29 30 31 Finds the square root of the given number by going from 0 to the 32 given number and seeing if that number squared is within 0001 of the 33 given number 34 35 double range x 36 for double i 0 0 i x i i 0001 37 if Math abs i i x Math abs range range x 38 range i 39 40 41 42 43 return range 44 45 46 47 48 Put a short phrase describing the static method myMethod here 49 50 51 52 Main method 53 54 param args 55 the command line arguments 56 57 public static void main String args 58 SimpleReader in new SimpleReader1L 59 SimpleWriter out new SimpleWriter1L 60 Page 1 Newton1and2 java Thursday January 27 2022 2 16 PM 61 Put your main program code here it may call myMethod as shown 62 63 64 65 Asks for the user to input the number a number to find the square 66 root of 67 68 out print What number do you want to find the square root of 69 double x in nextDouble 70 71 72 Calls the sqrt method and prints out the square root 73 74 double root sqrt x 75 out print The square root is root 76 77 Close input and output streams 78 79 in close 80 out close 81 82 83 84 Page 2


View Full Document

UIUC SOC 100 - Newton 1

Download Newton 1
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Newton 1 and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Newton 1 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?