Function Call Trace public class Newton {

Slides:



Advertisements
Similar presentations
Continuation of chapter 6…. Nested while loop A while loop used within another while loop is called nested while loop. Q. An illustration to generate.
Advertisements

1 public class Newton { public static double sqrt(double c) { double epsilon = 1E-15; if (c < 0) return Double.NaN; double t = c; while (Math.abs(t - c/t)
Introduction to Computer Science Robert Sedgewick and Kevin Wayne Recursive Factorial Demo pubic class Factorial {
Session 3 Algorithm. Algorithm Algorithm is a set of steps that are performed to solve a problem. The example below describes an algorithm Example Check.
Overloading methods review When is the return statement required? What do the following method headers tell us? public static int max (int a, int b)
1 COMP 110 More Arrays Tabitha Peck M.S. April 2, 2008 MWF 3-3:50 pm Philips 367.
Lec2_Java1 4 Data Types 4 Operators 4 Control Flow Statements 4 Arrays 4 Functions -- Static Methods 4 View Classes as modules Introduction to the Java.
Copyright © Curt Hill Mathematics Functions An example of static methods.
Ics202 Data Structures. class Array { protected Object[] data; protected int base; public Array (int n, int m) { data = new Object[n]; base = m; } public.
2.1 Functions Introduction to Programming in Java: An Interdisciplinary Approach · Robert Sedgewick and Kevin Wayne · Copyright © 2008 · October 21, 2015.
Working with arrays (we will use an array of double as example)
2.1 Functions Introduction to Programming in Java: An Interdisciplinary Approach · Robert Sedgewick and Kevin Wayne · Copyright © 2008 · 9/10/08 9/10/08.
Mixing integer and floating point numbers in an arithmetic operation.
Recap of Functions. Functions in Java f x y z f (x, y, z) Input Output Algorithm Allows you to clearly separate the tasks in a program. Enables reuse.
Public class Edo1 { private static double euler(double y, double h, double t, Derivada d) { return y + h * d.f(y, t); } public static void euler(double.
Methods. Methods also known as functions or procedures. Methods are a way of capturing a sequence of computational steps into a reusable unit. Methods.
Review TEST 2 Chapters 4,5,7. QUESTION For which type of operands does the == operator always work correctly: (a) int, (b) double, or (c) String?
The Math class Java provides certain math functions for us. The Math class contains methods and constants that can be very useful. The Math class is like.
2.1 Functions. Functions in Mathematics f x y z f (x, y, z) Domain Range.
Take out a piece of paper and PEN. The quiz starts ONE minute after the tardy bell rings. You will have 45 – 90 seconds per question. Determine the output.
FOR LOOP WALK THROUGH public class NestedFor { public static void main(String [] args) { for (int i = 1; i
TOPIC 6 Methods F Introducing Methods F Declaring Methods F Calling Methods F Passing Parameters F Pass by Value F Overloading Methods F Method Abstraction.
Introduction to array: why use arrays ?. Motivational example Problem: Write a program that reads in and stores away 5 double numbers After reading in.
Topic 9 Linear Search and Hash Tables. Announcements Participation due tomorrow FunSort explanation posted.
Method OverloadingtMyn1 Method overloading Methods of the same name can be declared in the same class, as long as they have different sets of parameters.
Computer Science 320 A First Program in Parallel Java.
Print Row Function void PrintRow(float x[ ][4],int i) { int j; for(j=0;j
import java.util.Scanner; class myCode { public static void main(String[] args) { Scanner input= new Scanner(System.in); int num1; System.out.println(“Enter.
Methods What is a method? Main Method the main method is where a stand alone Java program normally begins execution common compile error, trying.
Int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } 5 void main () { Int Sum; : Sum = fact (5); : } Factorial Program Using Recursion.
JAVA METHODS (FUNCTIONS). Why are they called methods? Java is a strictly object-oriented programming language Methods are functions inside of objects.
1 Lecture # 2. * Introducing Programming with an Example * Identifiers, Variables, and Constants * Primitive Data Types * Byte, short, int, long, float,
3/21/2016IT 2751 Tow kinds of Lists Array What can be done? What can be easily done? student 1 student 2 student 3 student 4 Linked List student 2 student.
Methods. Creating your own methods Java allows you to create custom methods inside its main body. public class Test { // insert your own methods right.
Object Oriented Programming Lecture 2: BallWorld.
Programming in Java Transitioning from Alice. Becomes not myFirstMethod but …. public static void main (String[] arg) { // code for testing classes goes.
Staples are our staple Building upon our solution.
Methods Matthew Harrison. Overview ● There are five main aspects of methods... ● 1) Modifiers – public, private ● 2) Method Name ● 3) Parameters ● 4)
Department of Computer Science
התוכנית: using System; using System.Collections.Generic;
Arrays 3/4 By Pius Nyaanga.
using System; namespace Demo01 { class Program
Computing Adjusted Quiz Total Score
Exam 2 Review 1.
محاور المحاضرة خوارزمية الفقاعات الهوائية (Bubble Sort)
Unit-2 Objects and Classes
Java Lesson 36 Mr. Kalmes.
Code Animation Examples
References, Objects, and Parameter Passing
Method Overloading in JAVA
Recursive GCD Demo public class Euclid {
References and Objects
class PrintOnetoTen { public static void main(String args[]) {
Java Programming with Multiple Classes
Why did the programmer quit his job?
A Java Application public class Hello { public static void main(String [] args) { System.out.println("Hello, World!"); } } public class.
Scope of variables class scopeofvars {
A Java Application public class Hello { public static void main(String [] args) { System.out.println("Hello, World!"); } } public class.
CSS161: Fundamentals of Computing
Linear Search and Hash Tables
Developing Java Applications with NetBeans
Introduction to Computer Science I.
Developing Java Applications with NetBeans
Local variables and how to recognize them
Arrays Wellesley College CS230 Lecture 02 Thursday, February 1
6.2 for Loops Example: for ( int i = 1; i
Arrays 3/4 June 3, 2019 ICS102: The course.
Chapter 6 Arrays.
PROGRAMMING ASSIGNMENT I
Presentation transcript:

Function Call Trace public class Newton { public static double sqrt(double c) { double epsilon = 1e-15; if (c < 0) return Double.NaN; double t = c; while (Math.abs(t - c/t) > epsilon * t) t = (c/t + t) / 2.0; return t; } public static void main(String[] args) { double[] a = new double[args.length]; for (int i = 0; i < args.length; i++) a[i] = Double.parseDouble(args[i]); for (int i = 0; i < a.length; i++) System.out.println(sqrt(a[i]));

Function Call Trace public class Newton { public static double sqrt(double c) { double epsilon = 1e-15; if (c < 0) return Double.NaN; double t = c; while (Math.abs(t - c/t) > epsilon * t) t = (c/t + t) / 2.0; return t; } public static void main(String[] args) { double[] a = new double[args.length]; for (int i = 0; i < args.length; i++) a[i] = Double.parseDouble(args[i]); for (int i = 0; i < a.length; i++) System.out.println(sqrt(a[i])); % java Newton 1 2 3

Function Call Trace public class Newton { public static double sqrt(double c) { double epsilon = 1e-15; if (c < 0) return Double.NaN; double t = c; while (Math.abs(t - c/t) > epsilon * t) t = (c/t + t) / 2.0; return t; } public static void main(String[] args) { double[] a = new double[args.length]; for (int i = 0; i < args.length; i++) a[i] = Double.parseDouble(args[i]); for (int i = 0; i < a.length; i++) System.out.println(sqrt(a[i])); { "1", "2", "3" } args[] { "1", "2", "3" } % java Newton 1 2 3

Function Call Trace public class Newton { public static double sqrt(double c) { double epsilon = 1e-15; if (c < 0) return Double.NaN; double t = c; while (Math.abs(t - c/t) > epsilon * t) t = (c/t + t) / 2.0; return t; } public static void main(String[] args) { double[] a = new double[args.length]; for (int i = 0; i < args.length; i++) a[i] = Double.parseDouble(args[i]); for (int i = 0; i < a.length; i++) System.out.println(sqrt(a[i])); args[] { "1", "2", "3" } a[] { 0.0, 0.0, 0.0 } % java Newton 1 2 3

Function Call Trace public class Newton { public static double sqrt(double c) { double epsilon = 1e-15; if (c < 0) return Double.NaN; double t = c; while (Math.abs(t - c/t) > epsilon * t) t = (c/t + t) / 2.0; return t; } public static void main(String[] args) { double[] a = new double[args.length]; for (int i = 0; i < args.length; i++) a[i] = Double.parseDouble(args[i]); for (int i = 0; i < a.length; i++) System.out.println(sqrt(a[i])); args[] { "1", "2", "3" } a[] { 0.0, 0.0, 0.0 } i % java Newton 1 2 3

Function Call Trace public class Newton { public static double sqrt(double c) { double epsilon = 1e-15; if (c < 0) return Double.NaN; double t = c; while (Math.abs(t - c/t) > epsilon * t) t = (c/t + t) / 2.0; return t; } public static void main(String[] args) { double[] a = new double[args.length]; for (int i = 0; i < args.length; i++) a[i] = Double.parseDouble(args[i]); for (int i = 0; i < a.length; i++) System.out.println(sqrt(a[i])); args[] { "1", "2", "3" } a[] { 1.0, 0.0, 0.0 } i % java Newton 1 2 3

Function Call Trace public class Newton { public static double sqrt(double c) { double epsilon = 1e-15; if (c < 0) return Double.NaN; double t = c; while (Math.abs(t - c/t) > epsilon * t) t = (c/t + t) / 2.0; return t; } public static void main(String[] args) { double[] a = new double[args.length]; for (int i = 0; i < args.length; i++) a[i] = Double.parseDouble(args[i]); for (int i = 0; i < a.length; i++) System.out.println(sqrt(a[i])); args[] { "1", "2", "3" } a[] { 1.0, 0.0, 0.0 } i 1 % java Newton 1 2 3

Function Call Trace public class Newton { public static double sqrt(double c) { double epsilon = 1e-15; if (c < 0) return Double.NaN; double t = c; while (Math.abs(t - c/t) > epsilon * t) t = (c/t + t) / 2.0; return t; } public static void main(String[] args) { double[] a = new double[args.length]; for (int i = 0; i < args.length; i++) a[i] = Double.parseDouble(args[i]); for (int i = 0; i < a.length; i++) System.out.println(sqrt(a[i])); args[] { "1", "2", "3" } a[] { 1.0, 2.0, 0.0 } i 1 % java Newton 1 2 3

Function Call Trace public class Newton { public static double sqrt(double c) { double epsilon = 1e-15; if (c < 0) return Double.NaN; double t = c; while (Math.abs(t - c/t) > epsilon * t) t = (c/t + t) / 2.0; return t; } public static void main(String[] args) { double[] a = new double[args.length]; for (int i = 0; i < args.length; i++) a[i] = Double.parseDouble(args[i]); for (int i = 0; i < a.length; i++) System.out.println(sqrt(a[i])); args[] { "1", "2", "3" } a[] { 1.0, 2.0, 0.0 } i 2 % java Newton 1 2 3

Function Call Trace public class Newton { public static double sqrt(double c) { double epsilon = 1e-15; if (c < 0) return Double.NaN; double t = c; while (Math.abs(t - c/t) > epsilon * t) t = (c/t + t) / 2.0; return t; } public static void main(String[] args) { double[] a = new double[args.length]; for (int i = 0; i < args.length; i++) a[i] = Double.parseDouble(args[i]); for (int i = 0; i < a.length; i++) System.out.println(sqrt(a[i])); args[] { "1", "2", "3" } a[] { 1.0, 2.0, 3.0 } i 2 % java Newton 1 2 3

Function Call Trace public class Newton { public static double sqrt(double c) { double epsilon = 1e-15; if (c < 0) return Double.NaN; double t = c; while (Math.abs(t - c/t) > epsilon * t) t = (c/t + t) / 2.0; return t; } public static void main(String[] args) { double[] a = new double[args.length]; for (int i = 0; i < args.length; i++) a[i] = Double.parseDouble(args[i]); for (int i = 0; i < a.length; i++) System.out.println(sqrt(a[i])); args[] { "1", "2", "3" } a[] { 1.0, 2.0, 3.0 } i 3 goes out of scope % java Newton 1 2 3

Function Call Trace public class Newton { public static double sqrt(double c) { double epsilon = 1e-15; if (c < 0) return Double.NaN; double t = c; while (Math.abs(t - c/t) > epsilon * t) t = (c/t + t) / 2.0; return t; } public static void main(String[] args) { double[] a = new double[args.length]; for (int i = 0; i < args.length; i++) a[i] = Double.parseDouble(args[i]); for (int i = 0; i < a.length; i++) System.out.println(sqrt(a[i])); args[] { "1", "2", "3" } a[] { 1.0, 2.0, 3.0 } i % java Newton 1 2 3

Function Call Trace public class Newton { public static double sqrt(double c) { double epsilon = 1e-15; if (c < 0) return Double.NaN; double t = c; while (Math.abs(t - c/t) > epsilon * t) t = (c/t + t) / 2.0; return t; } public static void main(String[] args) { double[] a = new double[args.length]; for (int i = 0; i < args.length; i++) a[i] = Double.parseDouble(args[i]); for (int i = 0; i < a.length; i++) System.out.println(sqrt(a[i])); 1.0 args[] { "1", "2", "3" } a[] { 1.0, 2.0, 3.0 } i 1.0 % java Newton 1 2 3

Function Call Trace public class Newton { public static double sqrt(double c) { double epsilon = 1e-15; if (c < 0) return Double.NaN; double t = c; while (Math.abs(t - c/t) > epsilon * t) t = (c/t + t) / 2.0; return t; } public static void main(String[] args) { double[] a = new double[args.length]; for (int i = 0; i < args.length; i++) a[i] = Double.parseDouble(args[i]); for (int i = 0; i < a.length; i++) System.out.println(sqrt(a[i])); 1.0 c 1.0 args[] { "1", "2", "3" } a[] { 1.0, 2.0, 3.0 } i 1.0 % java Newton 1 2 3

Function Call Trace public class Newton { public static double sqrt(double c) { double epsilon = 1e-15; if (c < 0) return Double.NaN; double t = c; while (Math.abs(t - c/t) > epsilon * t) t = (c/t + t) / 2.0; return t; } public static void main(String[] args) { double[] a = new double[args.length]; for (int i = 0; i < args.length; i++) a[i] = Double.parseDouble(args[i]); for (int i = 0; i < a.length; i++) System.out.println(sqrt(a[i])); c 1.0 args[] { "1", "2", "3" } a[] { 1.0, 2.0, 3.0 } i % java Newton 1 2 3

Function Call Trace public class Newton { public static double sqrt(double c) { double epsilon = 1e-15; if (c < 0) return Double.NaN; double t = c; while (Math.abs(t - c/t) > epsilon * t) t = (c/t + t) / 2.0; return t; } public static void main(String[] args) { double[] a = new double[args.length]; for (int i = 0; i < args.length; i++) a[i] = Double.parseDouble(args[i]); for (int i = 0; i < a.length; i++) System.out.println(sqrt(a[i])); c 1.0 args[] { "1", "2", "3" } a[] { 1.0, 2.0, 3.0 } i % java Newton 1 2 3

Function Call Trace public class Newton { public static double sqrt(double c) { double epsilon = 1e-15; if (c < 0) return Double.NaN; double t = c; while (Math.abs(t - c/t) > epsilon * t) t = (c/t + t) / 2.0; return t; } public static void main(String[] args) { double[] a = new double[args.length]; for (int i = 0; i < args.length; i++) a[i] = Double.parseDouble(args[i]); for (int i = 0; i < a.length; i++) System.out.println(sqrt(a[i])); c t 1.0 1.0 args[] { "1", "2", "3" } a[] { 1.0, 2.0, 3.0 } i % java Newton 1 2 3

Function Call Trace public class Newton { public static double sqrt(double c) { double epsilon = 1e-15; if (c < 0) return Double.NaN; double t = c; while (Math.abs(t - c/t) > epsilon * t) t = (c/t + t) / 2.0; return t; } public static void main(String[] args) { double[] a = new double[args.length]; for (int i = 0; i < args.length; i++) a[i] = Double.parseDouble(args[i]); for (int i = 0; i < a.length; i++) System.out.println(sqrt(a[i])); c t 1.0 1.0 args[] { "1", "2", "3" } a[] { 1.0, 2.0, 3.0 } i % java Newton 1 2 3

Function Call Trace public class Newton { public static double sqrt(double c) { double epsilon = 1e-15; if (c < 0) return Double.NaN; double t = c; while (Math.abs(t - c/t) > epsilon * t) t = (c/t + t) / 2.0; return t; } public static void main(String[] args) { double[] a = new double[args.length]; for (int i = 0; i < args.length; i++) a[i] = Double.parseDouble(args[i]); for (int i = 0; i < a.length; i++) System.out.println(sqrt(a[i])); c t 1.0 1.0 args[] 1.0 { "1", "2", "3" } a[] { 1.0, 2.0, 3.0 } i 1.0 % java Newton 1 2 3

Function Call Trace public class Newton { public static double sqrt(double c) { double epsilon = 1e-15; if (c < 0) return Double.NaN; double t = c; while (Math.abs(t - c/t) > epsilon * t) t = (c/t + t) / 2.0; return t; } public static void main(String[] args) { double[] a = new double[args.length]; for (int i = 0; i < args.length; i++) a[i] = Double.parseDouble(args[i]); for (int i = 0; i < a.length; i++) System.out.println(sqrt(a[i])); args[] { "1", "2", "3" } a[] { 1.0, 2.0, 3.0 } i 1.0 % java Newton 1 2 3 1.0

Function Call Trace public class Newton { public static double sqrt(double c) { double epsilon = 1e-15; if (c < 0) return Double.NaN; double t = c; while (Math.abs(t - c/t) > epsilon * t) t = (c/t + t) / 2.0; return t; } public static void main(String[] args) { double[] a = new double[args.length]; for (int i = 0; i < args.length; i++) a[i] = Double.parseDouble(args[i]); for (int i = 0; i < a.length; i++) System.out.println(sqrt(a[i])); args[] { "1", "2", "3" } a[] { 1.0, 2.0, 3.0 } i 1 % java Newton 1 2 3 1.0

Function Call Trace public class Newton { public static double sqrt(double c) { double epsilon = 1e-15; if (c < 0) return Double.NaN; double t = c; while (Math.abs(t - c/t) > epsilon * t) t = (c/t + t) / 2.0; return t; } public static void main(String[] args) { double[] a = new double[args.length]; for (int i = 0; i < args.length; i++) a[i] = Double.parseDouble(args[i]); for (int i = 0; i < a.length; i++) System.out.println(sqrt(a[i])); 2.0 c 2.0 args[] { "1", "2", "3" } a[] { 1.0, 2.0, 3.0 } i 1 2.0 % java Newton 1 2 3 1.0

Function Call Trace public class Newton { public static double sqrt(double c) { double epsilon = 1e-15; if (c < 0) return Double.NaN; double t = c; while (Math.abs(t - c/t) > epsilon * t) t = (c/t + t) / 2.0; return t; } public static void main(String[] args) { double[] a = new double[args.length]; for (int i = 0; i < args.length; i++) a[i] = Double.parseDouble(args[i]); for (int i = 0; i < a.length; i++) System.out.println(sqrt(a[i])); c 2.0 args[] { "1", "2", "3" } a[] { 1.0, 2.0, 3.0 } i 1 % java Newton 1 2 3 1.0

Function Call Trace public class Newton { public static double sqrt(double c) { double epsilon = 1e-15; if (c < 0) return Double.NaN; double t = c; while (Math.abs(t - c/t) > epsilon * t) t = (c/t + t) / 2.0; return t; } public static void main(String[] args) { double[] a = new double[args.length]; for (int i = 0; i < args.length; i++) a[i] = Double.parseDouble(args[i]); for (int i = 0; i < a.length; i++) System.out.println(sqrt(a[i])); c 2.0 args[] { "1", "2", "3" } a[] { 1.0, 2.0, 3.0 } i 1 % java Newton 1 2 3 1.0

Function Call Trace public class Newton { public static double sqrt(double c) { double epsilon = 1e-15; if (c < 0) return Double.NaN; double t = c; while (Math.abs(t - c/t) > epsilon * t) t = (c/t + t) / 2.0; return t; } public static void main(String[] args) { double[] a = new double[args.length]; for (int i = 0; i < args.length; i++) a[i] = Double.parseDouble(args[i]); for (int i = 0; i < a.length; i++) System.out.println(sqrt(a[i])); c t 2.0 2.0 args[] { "1", "2", "3" } a[] { 1.0, 2.0, 3.0 } i 1 % java Newton 1 2 3 1.0

Function Call Trace public class Newton { public static double sqrt(double c) { double epsilon = 1e-15; if (c < 0) return Double.NaN; double t = c; while (Math.abs(t - c/t) > epsilon * t) t = (c/t + t) / 2.0; return t; } public static void main(String[] args) { double[] a = new double[args.length]; for (int i = 0; i < args.length; i++) a[i] = Double.parseDouble(args[i]); for (int i = 0; i < a.length; i++) System.out.println(sqrt(a[i])); c t 2.0 2.0 args[] { "1", "2", "3" } a[] { 1.0, 2.0, 3.0 } i 1 % java Newton 1 2 3 1.0

Function Call Trace public class Newton { public static double sqrt(double c) { double epsilon = 1e-15; if (c < 0) return Double.NaN; double t = c; while (Math.abs(t - c/t) > epsilon * t) t = (c/t + t) / 2.0; return t; } public static void main(String[] args) { double[] a = new double[args.length]; for (int i = 0; i < args.length; i++) a[i] = Double.parseDouble(args[i]); for (int i = 0; i < a.length; i++) System.out.println(sqrt(a[i])); c t 2.0 1.41 args[] { "1", "2", "3" } a[] { 1.0, 2.0, 3.0 } i 1 % java Newton 1 2 3 1.0

Function Call Trace public class Newton { public static double sqrt(double c) { double epsilon = 1e-15; if (c < 0) return Double.NaN; double t = c; while (Math.abs(t - c/t) > epsilon * t) t = (c/t + t) / 2.0; return t; } public static void main(String[] args) { double[] a = new double[args.length]; for (int i = 0; i < args.length; i++) a[i] = Double.parseDouble(args[i]); for (int i = 0; i < a.length; i++) System.out.println(sqrt(a[i])); c t 2.0 1.41 args[] { "1", "2", "3" } a[] { 1.0, 2.0, 3.0 } i 1 % java Newton 1 2 3 1.0

Function Call Trace public class Newton { public static double sqrt(double c) { double epsilon = 1e-15; if (c < 0) return Double.NaN; double t = c; while (Math.abs(t - c/t) > epsilon * t) t = (c/t + t) / 2.0; return t; } public static void main(String[] args) { double[] a = new double[args.length]; for (int i = 0; i < args.length; i++) a[i] = Double.parseDouble(args[i]); for (int i = 0; i < a.length; i++) System.out.println(sqrt(a[i])); c t 2.0 1.41 args[] 1.414213562373095 { "1", "2", "3" } a[] { 1.0, 2.0, 3.0 } i 1 1.414213562373095 % java Newton 1 2 3 1.0

Function Call Trace public class Newton { public static double sqrt(double c) { double epsilon = 1e-15; if (c < 0) return Double.NaN; double t = c; while (Math.abs(t - c/t) > epsilon * t) t = (c/t + t) / 2.0; return t; } public static void main(String[] args) { double[] a = new double[args.length]; for (int i = 0; i < args.length; i++) a[i] = Double.parseDouble(args[i]); for (int i = 0; i < a.length; i++) System.out.println(sqrt(a[i])); args[] { "1", "2", "3" } a[] { 1.0, 2.0, 3.0 } i 1 1.414213562373095 % java Newton 1 2 3 1.0 1.414213562373095

Function Call Trace public class Newton { public static double sqrt(double c) { double epsilon = 1e-15; if (c < 0) return Double.NaN; double t = c; while (Math.abs(t - c/t) > epsilon * t) t = (c/t + t) / 2.0; return t; } public static void main(String[] args) { double[] a = new double[args.length]; for (int i = 0; i < args.length; i++) a[i] = Double.parseDouble(args[i]); for (int i = 0; i < a.length; i++) System.out.println(sqrt(a[i])); args[] { "1", "2", "3" } a[] { 1.0, 2.0, 3.0 } i 2 % java Newton 1 2 3 1.0 1.414213562373095

Function Call Trace public class Newton { public static double sqrt(double c) { double epsilon = 1e-15; if (c < 0) return Double.NaN; double t = c; while (Math.abs(t - c/t) > epsilon * t) t = (c/t + t) / 2.0; return t; } public static void main(String[] args) { double[] a = new double[args.length]; for (int i = 0; i < args.length; i++) a[i] = Double.parseDouble(args[i]); for (int i = 0; i < a.length; i++) System.out.println(sqrt(a[i])); 3.0 c 3.0 args[] { "1", "2", "3" } a[] { 1.0, 2.0, 3.0 } i 2 3.0 % java Newton 1 2 3 1.0 1.414213562373095

Function Call Trace public class Newton { public static double sqrt(double c) { double epsilon = 1e-15; if (c < 0) return Double.NaN; double t = c; while (Math.abs(t - c/t) > epsilon * t) t = (c/t + t) / 2.0; return t; } public static void main(String[] args) { double[] a = new double[args.length]; for (int i = 0; i < args.length; i++) a[i] = Double.parseDouble(args[i]); for (int i = 0; i < a.length; i++) System.out.println(sqrt(a[i])); c 3.0 args[] 1.7320508075688772 { "1", "2", "3" } a[] { 1.0, 2.0, 3.0 } i 2 1.7320508075688772 % java Newton 1 2 3 1.0 1.414213562373095

Function Call Trace public class Newton { public static double sqrt(double c) { double epsilon = 1e-15; if (c < 0) return Double.NaN; double t = c; while (Math.abs(t - c/t) > epsilon * t) t = (c/t + t) / 2.0; return t; } public static void main(String[] args) { double[] a = new double[args.length]; for (int i = 0; i < args.length; i++) a[i] = Double.parseDouble(args[i]); for (int i = 0; i < a.length; i++) System.out.println(sqrt(a[i])); args[] { "1", "2", "3" } a[] { 1.0, 2.0, 3.0 } i 2 % java Newton 1 2 3 1.0 1.414213562373095 1.7320508075688772

Function Call Trace public class Newton { public static double sqrt(double c) { double epsilon = 1e-15; if (c < 0) return Double.NaN; double t = c; while (Math.abs(t - c/t) > epsilon * t) t = (c/t + t) / 2.0; return t; } public static void main(String[] args) { double[] a = new double[args.length]; for (int i = 0; i < args.length; i++) a[i] = Double.parseDouble(args[i]); for (int i = 0; i < a.length; i++) System.out.println(sqrt(a[i])); args[] { "1", "2", "3" } a[] { 1.0, 2.0, 3.0 } i 3 % java Newton 1 2 3 1.0 1.414213562373095 1.7320508075688772

Function Call Trace public class Newton { public static double sqrt(double c) { double epsilon = 1e-15; if (c < 0) return Double.NaN; double t = c; while (Math.abs(t - c/t) > epsilon * t) t = (c/t + t) / 2.0; return t; } public static void main(String[] args) { double[] a = new double[args.length]; for (int i = 0; i < args.length; i++) a[i] = Double.parseDouble(args[i]); for (int i = 0; i < a.length; i++) System.out.println(sqrt(a[i])); args[] { "1", "2", "3" } a[] { 1.0, 2.0, 3.0 } % java Newton 1 2 3 1.0 1.414213562373095 1.7320508075688772