# CSCI 2170 Lecture 3: Expressions

14 views1 pages
11 Oct 2019
School
Course
Professor
AP Computer Science Name(s): ________________________
Solving Expressions:
Integer math only results in integer values eliminating any fractional values (e.g., 5 / 4 -> 1)
Real Numbers (double) keep fractional precision (e.g., 2.5 * 3.5 -> 8.75)
Strings can be appended (concatenated) with a plus “+” (e.g., “bird” + “dog” -> “birddog” )
Precedence order (all numbers and strings): () before * / % before + - , then left to right
Integer and Real Number results in a Real Number (double) (e.g., 2.5 * 3 -> 7.5)
String and any number results in a String (e.g., “Area ” + 51 -> “Area 51” )
Expressions:
Expression to Solve
12 / 5 + 8 / 4
3 * 4 + 15 / 2
-(1 + 2 * 3 + (1 + 2) * 3)
42 % 5 + 16 % 3
2.5 * 2 + 17 / 4
4.5 / 3 / 2 + 1
2 + 6 + "cse 142"
"cse 142" + 2 + 6
1 + 9 / 2 * 2.0
46 / 3 / 2.0 / 3 * 4/5
50 / 9 / 2.0 + 200 / 10 / (5.0 / 2)
Unlock document

This preview shows half of the first page of the document.
Unlock all 1 pages and 3 million more documents.