WUSTL CSE 131 - sp14_5 (55 pages)

Previewing pages 1, 2, 3, 4, 25, 26, 27, 52, 53, 54, 55 of 55 page document View the full content.
View Full Document

sp14_5



Previewing pages 1, 2, 3, 4, 25, 26, 27, 52, 53, 54, 55 of actual document.

View the full content.
View Full Document
View Full Document

sp14_5

95 views


Pages:
55
School:
Washington University in St. Louis
Course:
Cse 131 - Computer Science I
Computer Science I Documents

Unformatted text preview:

Module 5 Methods Introduction to Programming in Java An Interdisciplinary Approach Robert Sedgewick and Kevin Wayne Copyright 2002 2010 1 14 19 07 10 10 AM Methods x y z f f x y z A Foundation for Programming any program you might want to write objects methods build bigger programs and reuse code graphics sound and image I O arrays conditionals and loops Math primitive data types text I O assignment statements 3 Anatomy of a Java Method a k a Function Java methods Easy to write your own 2 0 input f x x output 1 414213 4 Flow of Control Key point Methods provide a new way to control the flow of execution 5 Flow of Control Key point Functions provide a new way to control the flow of execution 6 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 7 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 8 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 1 2 3 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 java Newton 1 2 3 9 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



View Full Document

Access the best Study Guides, Lecture Notes and Practice Exams

Loading Unlocking...
Login

Join to view sp14_5 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 sp14_5 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?