





Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!






CS201 1/
© 2004 Illinois Institute of Technology
CS201 3/
CS201 4/
CS201 5/
CS201 6/
CS201 7/
CS201 8/
CS201 9/
CS201 10/
CS201 11/
CS201 12/
CS201 19/
true false
boolean isEmpty; boolean passed, failed;
CS201 20/
dataType variableName = initialValue;
dataType variable1 = initialValue1, variable2 = initialValue2, …;
CS201 21/
CS201 22/
CS201 23/
CS201 24/
dataType variable2 = variable1;
CS201 25/
Any type in right column can be assigned to type in left column:
Data Type Compatible Data Types byte byte short byte, short int byte, short, int, char long byte, short, int, long, char float float, byte, short, int, long, char double float, double, byte, short, int, long, char boolean boolean char char
CS201 26/
float salesTax = .05f; double taxRate = salesTax;
double taxRate = .05; float salesTax = taxRate;
CS201 27/
"Hello" "Hello world" "The value of x is "
CS201 28/
String hello = "Hello"; String there = "there"; String greeting = hello + ' ' + there; System.out.println( greeting );
Hello there
CS201 29/
System.out.println( "Never pass a water fountain without taking a drink" );
unclosed string literal ')' expected
**System.out.println( "Never pass a water fountain"
CS201 30/
Character Escape Sequence Newline \n Tab \t Double quotes " Single quote ' Backslash \ Backspace \b Carriage return \r Form feed \f
CS201 37/
int numPlayers = 10; // numPlayers holds 10 numPlayers = 8; // numPlayers now holds 8
int legalAge = 18; int voterAge = legalAge;
int height = weight * 2; // weight is not defined int weight = 20;
illegal forward reference
CS201 38/
CS201 39/
CS201 40/
CS201 41/
int pennies = 2 * 25 + 3 * 10 + 2 * 5; = 50 + 30 + 10 = 90
CS201 42/
2y
// incorrect! double result = x / 2 * y;
// correct double result = x / ( 2 * y );
CS201 43/
CS201 44/
CS201 45/
CS201 46/
CS201 47/
(dataType)( expression )
CS201 48/
count++; // count = count + 1; count--; // count = count - 1;