Parentheses and can be used for more complicated

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: - 0123 is handled as 83(10) [ie. 1*8*8+ 2*8 + 3] - display 83 !! Can also be represented as Octal values: 0.. [ Be careful: 0123 123 ] Common operators for numbers: +, -, *, /, % Precedence of *, /, and % are higher than + and -. Example: 3-2*4 gives -5 (* is calculated before -). Parentheses ( and ) can be used for more complicated calculations. Example: final_mark = (assignment_mark + (testA + testB)/2)/2 * 0.3 + exam_mark * 0.7; 2 special operators: ++ and --: increment and decrement a variable by 1. Example: count++; is the same as count = count + 1; and counter += 1; count--; is the same as count = count - 1; and counter -= 1; (CS1301) Introduction to Computer Programming City Univ of HK / Dept of CS / Helena Wong http://www.cs.cityu.edu.hk/~helena 4. Program Structure III - 11 Data Types Booleans A Boolean value is either true or false (cf. a numberic value maybe 1, 100, -1, 3.14, ...). a Boolean value can only be true or false true is equivalent to 1 and false is equivalent to 0. Often used in Decision Making: Equality and Relational Operators To obtain true / false values based on comparison results: Sample JavaScript condition Equality operators x == y x != y x is equal to y x is not equal to y The results could only be true / false (Boolean values) Meani...
View Full Document

Ask a homework question - tutors are online