230 likes | 402 Views
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
E N D
COP3502: Introduction to CIS I Lecture 5
variables type, name, value declaration: inti; Assignment: inti = 5; double pi = 3.14; String name = Bob;
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
initial values • byte = 0 • short = 0 • int = 0 • long = 0L • float = 0.0f • double = 0.0d • boolean = false • char = “\u0000” • String = null
reserved keywords syntax tip: Don’t name your variable anything highlighted pink or blue by Sublime
loss of precision We cannot represent an infinite set of real numbers with a finite amount of memory!
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…..
order of operations style tip: ALWAYS USE PARENTHESES x + y * z
order of operations style tip: ALWAYS USE PARENTHESES x + (y * z)
order of operations style tip: ALWAYS USE PARENTHESES “The result is ” + 5 + 10 vs. “The result is ” + (5 + 10)
functions public static voidmain(Stringargs[]) public static voidnewLine() { System.out.println(); } public static voidthreeLines() { newLine(); newLine(); newLine(); }
parameters public static voidprintGreeting(Stringname) { System.out.println(“Hello, there ” + name); }
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…..
String args[] arg[0] – first argument args[1] – second argument ….
if condition if (boolean condition) { // Do something }
if-else condition if (boolean condition) { // Do something } else { // Do something else }
else if condition if (boolean condition) { // Do something } else if (boolean condition) { // Do something else } else { // Do yet ANOTHER thing }