1 / 23

Lecture 5

COP3502: Introduction to CIS I. Lecture 5. y. u pdated syllabus. v ariables type, name, value d eclaration: i nt i ; Assignment: i nt i = 5; d ouble pi = 3.14; String name = Bob;. types b yte = 8-bits s hort = 16-bits i nt = 32-bits long = 64-bits f loat = 32-bits

iren
Download Presentation

Lecture 5

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. COP3502: Introduction to CIS I Lecture 5

  2. y

  3. updated syllabus

  4. variables type, name, value declaration: inti; Assignment: inti = 5; double pi = 3.14; String name = Bob;

  5. types • byte = 8-bits • short = 16-bits • int = 32-bits • long = 64-bits • float = 32-bits • double = 64-bits • boolean = not well defined • char = 16-bits

  6. initial values • byte = 0 • short = 0 • int = 0 • long = 0L • float = 0.0f • double = 0.0d • boolean = false • char = “\u0000” • String = null

  7. reserved keywords syntax tip: Don’t name your variable anything highlighted pink or blue by Sublime

  8. loss of precision We cannot represent an infinite set of real numbers with a finite amount of memory!

  9. Math class • Math.pow(x, y) • Math.sqrt(x) • Math.sin(x) • Math.log(x) • Math.abs(x) • Math.PI = 3.14….. • Math.E = 2.71…..

  10. order of operations style tip: ALWAYS USE PARENTHESES x + y * z

  11. order of operations style tip: ALWAYS USE PARENTHESES x + (y * z)

  12. order of operations style tip: ALWAYS USE PARENTHESES “The result is ” + 5 + 10 vs. “The result is ” + (5 + 10)

  13. functions

  14. functions public static voidmain(Stringargs[]) public static voidnewLine() { System.out.println(); } public static voidthreeLines() { newLine(); newLine(); newLine(); }

  15. parameters

  16. parameters public static voidprintGreeting(Stringname) { System.out.println(“Hello, there ” + name); }

  17. arguments • Math.pow(x, y) • Math.sqrt(x) • Math.sin(x) • Math.log(x) • Math.abs(x) • Math.PI = 3.14….. • Math.E = 2.71…..

  18. command line arguments

  19. String args[] arg[0] – first argument args[1] – second argument ….

  20. if condition if (boolean condition) { // Do something }

  21. if-else condition if (boolean condition) { // Do something } else { // Do something else }

  22. else if condition if (boolean condition) { // Do something } else if (boolean condition) { // Do something else } else { // Do yet ANOTHER thing }

More Related